I want to use switch statements in my program. I've got my code working already but want to use switch statements. How do I do it? Here is what i got so far. import java.util.Scanner; public class ReviewApplication { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); double sum = 0; double difference = 0; double product = 0; double divide = 0; double[] array = new double[5]; System.out.print(" Enter 5 floating point numbers: "); for (int i = 0; i < array.length; i++) { array[i] = keyboard.nextDouble(); sum = sum + array[i]; } char choice; while (1==1) { choice = processMenu(); if(choice == 'a') { System.out.println("the sum is " + sum);} else if (choice =='s') { difference = array[0]; for (int i = 0; i < array.length; i++) difference = difference - array[i];

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I want to use switch statements in my program. I've got my code working already but want to use switch statements. How do I do it? Here is what i got so far.


import java.util.Scanner;

public class ReviewApplication {

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);
double sum = 0;
double difference = 0;
double product = 0;
double divide = 0;

double[] array = new double[5];

System.out.print(" Enter 5 floating point numbers: ");
for (int i = 0; i < array.length; i++) {
array[i] = keyboard.nextDouble();
sum = sum + array[i];
}
char choice;
while (1==1) {

choice = processMenu();

if(choice == 'a') {
System.out.println("the sum is " + sum);}

else if (choice =='s') {
difference = array[0];
for (int i = 0; i < array.length; i++)
difference = difference - array[i];

System.out.println("the difference is" + difference);}

else if (choice == 'm') {
product = array[0];
for (int i = 1; i < array.length; i++){
product = product * array[i];}
System.out.println("the product is " + product);
}
else if (choice == 'd') {
divide = array[0];
for (int i = 1; i < array.length; i++){
divide = divide/array[i];
}
System.out.println("the answer is" + divide);
}
else if (choice =='q')
{
System.out.println("Thanks for playing!");
System.exit(0);
} // end of main
}
public static char processMenu( ){
Scanner keyboard = new Scanner(System.in);
char response ;
while(1==1) {
System.out.println("Enter a to add numbers");
System.out.println("Enter s to subtract");
System.out.println("Enter m to multiply");
System.out.println("Enter d to divide");
System.out.println("Enter q to exit");
System.out.print(">>> ");
response = keyboard.next().charAt(0);
if (response == 'a' || response == 's' || response == 'm' ||
response == 'd'|| response == 'q') {
break;
}
else {

System.out.println("Invalid menu slection. Try again.");
}
}

return response;
}
}



 

 

Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education