Question: in Java, I ' m stuck on figuring out how to make the program so that that the user types the commands ' a '

in Java, I'm stuck on figuring out how to make the program so that that the user types the commands 'a' and 'b' and the program stores those as decimal values. In the photo, there is an interface which I'd like the menu to display and the "0.000" to be replaced with the user input.
A=0.000
B=0.000
Enter a value for A
Enter a value for B
This is what I have thus far:
import java.util.Scanner;
public class App {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
Character command ='_';
// loop until user quits
while (command !='q'){
printMenu();
System.out.print("Enter a command: ");
command = menuGetCommand(scan);
executeCommand(scan, command);
if (command =='a'){
System.out.println("Enter a number: ");
double numA = scan.nextDouble();
if (numA >0){
System.out.printf("A ="+ numA);
printMenu();
}
}
if (command =='b'){
System.out.println("Enter a number: ");
double numB = scan.nextDouble();
printMenu();
System.out.printf("B =", numB);
}
}
scan.close();
}
//
// menu functions
//
private static void printMenuLine(){
System.out.println(
"----------------------------------------------------------"
);
}
private static void printMenuCommand(Character command, String desc){
System.out.printf("%s\t%s
", command, desc);
}
// prints the menu
public static void printMenu(){
printMenuLine();
System.out.println("ChavviCalc");
printMenuLine();
System.out.println("A =0.000"+""+"B =0.000");
printMenuLine();
printMenuCommand('a', "Enter a value for A");
printMenuCommand('b', "Enter a value for B");
printMenuCommand('+', "Add");
printMenuCommand('-', "Subtract");
printMenuCommand('*', "Multiply");
printMenuCommand('/', "Divide");
printMenuCommand('c', "Clear");
printMenuCommand('q', "Quit");
printMenuLine();
}
// get first character from input
private static Character menuGetCommand(Scanner scan)
{
Character command ='_';
String rawInput = scan.nextLine();
if (rawInput.length()>0){
rawInput = rawInput.toLowerCase();
command = rawInput.charAt(0);
}
return command;
}
// calculator functions
private static Boolean executeCommand(Scanner scan, Character command){
Boolean success = true;
switch (command){
case 'q':
System.out.println("Thank you for using Chavvi Calc");
break;
case 'a','b':
break;
default:
System.out.println("ERROR: Unknown commmand");
success = false;
}
return success;
}
}
in Java, I ' m stuck on figuring out how to make

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!