Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Program. Objectives Practice conditional statements, and method. Problem Write a program to simulate a simple calculator. In your program ask the user to

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribedIn Java Program.
Objectives Practice conditional statements, and method. Problem Write a program to simulate a simple calculator. In your program ask the user to enter an operation selected from the menu, then ask for the two operands. Calculate the result and display the result it on the screen. sample output To do addition enter + To do multiplication enter To do subtraction enter To do exponent enter to do division enter / To do modulus enter % Enter the operation: * Enter a number between 0-9: 5 Enter a number between 0-9: 3 five multiply three is 15 Requirements Must provide the required methods . Must provide the exact same output Main method must have one line of code only Program runs however many times the user says Proper naming Proper commenting Proper indentation Must use if and switch statements Methods Public static void main(String [] args): this method has only one line of code and that is calling the run method Public static void menu (): this method prints the menu provided in the sample output, refer to the output given below. public static int calculate (int operandi, int operand2, String operation): this method must have the following conditional statements for all the operations. The following are the two sample. Make sure to use equals method from the string class and not. If the operation is then your method should return Methods Public static void main(String || args): this method has only one line of code and that is calling the run method Public static void menu 0: this method prints the menu provided in the sample output. refer to the output given below. public static int calculate (int operandi, int operand2, String operation): this method must have the following conditional statements for all the operations. The following are the two sample. Make sure to use equals method from the string class and not. If the operation is then your method should return Math.pow(oprl, opr2). Must use switch statements switch(operation) case ***"; return oprl * opr2; // Rest of the case statements public static String convertOperand(int opr): this method translate the operand oprl to its word version. This method must have ten conditions for numbers 0-9 such as the following: if(opr == 1) {return "one" } 1/rest of the conditional statements Public static String convertOperation(String operation): this method translates the operation to its word version. Must have 6 conditions, one for each operation similar to the followings. If operation.equals("**")) return "multiply": } //rest of the if statements public static void run 0: Create a Scanner object asks the user the number of the times they want to run the program .creates a for loop and in the for loop 1. call the method menu 2. prompt the user to get the user's choice from the menu 3. prompt the user to enter the first operand between 0-9 4. prompt the user to get the second operand between 0-9 5. call the method calculate and pass the two operands and the operation to it. Calculate(5,6,"**") should return 30. Calculate(3,6,"+") should return 9 6. call the method convertOpernad() and pass the first public static void run (): Create a Scanner object asks the user the number of the times they want to run the program .creates a for loop and in the for loop 1. call the method menu 2. prompt the user to get the user's choice from the menu 3. prompt the user to enter the first operand between 0-9 4. prompt the user to get the second operand between 0-9 5. call the method calculate and pass the two operands and the operation to it. Calculate(5,6,***) should return 30. Calculate(3,6,"+") should return 9 6. call the method convertOpernad() and pass the first operand to it to get the word for the operand. For example convertOperand(5) should return "five". Convert operand(6) should return "six 7. call the method convertOpernad() and pass the second operand to it to get the word for the operand. For example convertOperand(5) should return "five" Convert operand() should return "six" 8. call the method convertOperation() to get the word for the operation. For example convertOperation(***) should return "multiply". convertOperation("+") should return plus 9. create a string from steps 5-9 and display the result on the screen sample output How many times do you want to use the software: 4 ***** To do addition enter + To do multiplication enter * To do subtraction enter - To do exponent enter * to do division enter / To do modulus enter % Enter the operation: / Enter a number between 0-9: 9 Enter a number between 0-9: 3 sample output How many times do you want to use the software: 4 To do addition enter + To do multiplication enter * To do subtraction enter - To do exponent enter to do division enter / To do modulus enter % **** Enter the operation: / Enter a number between 0-9: 9 Enter a number between 0-9: 3 ******** nine divided by three is 3 ******** To do addition enter To do multiplication enter * To do subtraction enter - To do exponent enter to do division enter / To do modulus enter % *** Enter the operation: * Enter a number between 0-9: 3 Enter a number between 0-9: 7 three multiply seven is 21 To do addition enter To do multiplication enter * To do subtraction enter To do exponent enter * to do division enter / To do modulus enter % Enter the operation: % Enter a number between 0-9: 9 Enter a number between 0-9: 2 To do multiplication enter To do subtraction enter - To do exponent enter A to do division enter / To do modulus enter Enter the operation: * Enter a number between 0-9: 3 Enter a number between 0-9: 7 three multiply seven is 21 To do addition enter + To do multiplication enter * To do subtraction enter To do exponent enter * to do division enter / To do modulus enter % *** Enter the operation: % Enter a number between 0-9: 9 Enter a number between 0-9: 2 nine modulus two is 1 To do addition enter + To do multiplication enter * To do subtraction enter To do exponent enter * to do division enter / To do modulus enter & Enter the operation: * Enter a number between 0-9: 5 Enter a number between 0-9: 6 five to the power of six is 15625

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

1. Who is responsible for resolving this dilemma?

Answered: 1 week ago