/* example of a menu driven program create a simple calculator that will add subtract multiply and divide values entered by the user */ import java.util.*; //used to include scanner public class...


/*

example of a menu driven program



create a simple calculator that will add subtract multiply and divide

values entered by the user

*/

import java.util.*; //used to include scanner



public class menuExample

{

public static void main(String args[])

{

//declare a scanner for user Input

Scanner userInput = new Scanner(System.in);

int choice;

int value1, value2

double.number; //hold result of integer value



do

{

//display our menu

System.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 input

choice = userInput.nextInt();



//switch the choice from user

switch(choice)

{

case 1://addition

System.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://subtraction

System.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://multiplication

System.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://division

System.out.println("division");

System.out.println("Please enter two values to be divided");

value1= userInput.nextInt();

value2 = userInput.nextInt();

number = (double)value1 / value2; //type cast

System.out.println(value1 + " / " + value2 + " = " + number);

break;

case 5://division

System.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://exit

System.out.println("You have chose exit!");

break;

default://default

System.out.println("You entered an invalid choice");

}

}while(choice != 5);





}//main

}//class


May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here