/*example of a menu driven programcreate a simple calculator that will add subtract multiply and dividevalues entered by the user*/import java.util.*; //used to include scannerpublic class menuExample{public static void main(String args[]){//declare a scanner for user InputScanner userInput = new Scanner(System.in);int choice;int value1, value2double.number; //hold result of integer valuedo{//display our menuSystem.out.println("*** Calculator v1.0***");System.out.println("1, Addition");System.out.println("2, Subtration");System.out.println("3, Multiplication");System.out.println("4, Division");System.out.println("5, Modulos");System.out.println("6. Exit");System.out.println("**********************");System.out.println("Please enter your choice:");//get user inputchoice = userInput.nextInt();//switch the choice from userswitch(choice){case 1://additionSystem.out.println("addition");System.out.println("Please enter two values to be added");value1 = userInput.nextInt();value2 = userInput.nextInt();System.out.println(value1 + " + " + value2 + " = " + (value1+value2);break;case 2://subtractionSystem.out.println("subraction");System.out.println("Please enter two values to be subtrated");value1 = userInput.nextInt();value2 = userInput.nextInt();System.out.println(value1 + " - " + value2 + " = " + (value1-value2);break;case 3://multiplicationSystem.out.println("multiplication");System.out.println("Please enter two values to be multiplicated");value1= userInput.nextInt();value2 = userInput.nextInt();System.out.println(value1 + " * " + value2 + " = " + (value18value2);break;case 4://divisionSystem.out.println("division");System.out.println("Please enter two values to be divided");value1= userInput.nextInt();value2 = userInput.nextInt();number = (double)value1 / value2; //type castSystem.out.println(value1 + " / " + value2 + " = " + number);break;case 5://divisionSystem.out.println("multiplication");System.out.println("Please enter two values to be divided");value1= userInput.nextInt();value2 = userInput.nextInt();System.out.println(value1 + " % " + value2 + " = " + (value1%value2);break;case 6://exitSystem.out.println("You have chose exit!");break;default://defaultSystem.out.println("You entered an invalid choice");}}while(choice != 5);}//main}//class
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here