I have some questions about java programming, im stuck on a couple things. I will attatch what I’ve got so far but here is what I have to do,
Enter a to add. |
Enter s to subtract. |
Enter m to multiply. |
Enter d to divide. |
Enter q to quit. |
Let me know what i am missing. Also how do I display a message and exit when the user enters “Q”?
Here is what i’ve 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;
boolean looper = true;
double[] array = new double[5];
String choice = processMenu();
boolean continueToRun = true;
System.out.print(” Enter 5 floating point numbers “);
for (int i = 0; i < array.length; i++){
array[i] = keyboard.nextDouble();
sum = sum + array[i];
}
System.out.println(sum);
processMenu();
switch (choice) {
case 1:
for (int i = 0; i < array.length; i++){
array[i] = keyboard.nextDouble();
sum = sum + array[i];
}
System.out.println(sum);
break;
case 2:
for (int i = 0; i < array.length; i++){
array[i] = keyboard.nextDouble();
difference = difference – array[i];}
System.out.println(“the difference is” + difference);
break;
case 3:
for (int i = 0; i < array.length; i++){
array[i] = keyboard.nextDouble();
product = product * array[i];}
System.out.println(“the product is” + product);
break;
case 4:
double total4 = 0;
for (int i = 0; i < array.length; i++){
total4 /= array[i];}
System.out.println(“the answer is” + total4);
}
break;
case 5:System.out.println(“enter q to exit”);
keyboard.nextLine();
if input =’q’; System.exit;
break;
while(looper); System.out.println();
System.out.println(“Thanks for playing!”);
keyboard.close();}
} // end of main
public static String processMenu( ){
Scanner keyboard = new Scanner(System.in);
String response = keyboard.nextLine();
do {
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.nextLine();
// keyboard.nextLine(); //clear enter key from keyboard buffer
if (response != “a” || response != “s” || response != “m” ||
response != “d”|| response != “q”) {
System.out.println(“Invalid menu slection. Try again.”);
}
}while (response == “a” || response == “s” || response == “m” ||
response == “d”|| response == “q”);
return response;
}
}
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more
Recent Comments