With this program you are going to design a math practice program for younger users. You will ask the user to enter two numbers. Only numbers may be entered. If the user enters a word, the program should disregard the entry and wait for an integer entry. There will not be another prompt if the user enters data other than whole numbers (integers).
Here is a sample run: Your static methods should accept two integers and return an integer. Do not worry about testing for division by 0 because that won't be one of the tests. Your methods will be named: addNumbers subtractNumbers multiplyNumbers divideNumbers The methods will be static. After each run, the program will ask if the user wishes to quit: Here is the prompt to quit the program: System.out.println("Enter 'Quit' to end the program."); Here are the prompts to read in the choices: System.out.println("Enter 1 to add the two numbers."); System.out.println("Enter 2 to subtract the second number from the first number."); System.out.println("Enter 3 to multiply the two numbers."); System.out.println("Enter 4 to divide the first number by the second number."); Here is the prompt to read in the two numbers: System.out.println("Enter two integers:"); Here is the welcome prompt: System.out.println("Welcome to *Mental Math Practice* where you can test your addition, subtraction, multiplication, and division."); Use a Scanner to read in the data from the console.
this is what the professor gave me
import java.util.Scanner;
/**
*
* @author dfreer
*/
public class MathTeacher {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Welcome to *Mental Math Practice* where you can
test your addition, subtraction, multiplication, and division.");
System.out.println("Enter two integers:");
System.out.println("Enter 1 to add the two numbers.");
System.out.println("Enter 2 to subtract the second number from the
first number.");
System.out.println("Enter 3 to multiply the two numbers.");
System.out.println("Enter 4 to divide the first number by the
second number.");
System.out.println("Enter 'Quit' to end the program.");
}
}
Code:
import java.util.Scanner;
public class MathTeacher {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int first=0,second=0,choice=0;
String quit ="";
System.out.println("Welcome to *Mental Math Practice*
where you can test your addition, subtraction, multiplication, and
division.");
do {
System.out.println("Enter two
integers:");
first=input.nextInt();
second=input.nextInt();
System.out.println("Enter 1 to add
the two numbers.");
System.out.println("Enter 2 to
subtract the second number from the first number.");
System.out.println("Enter 3 to
multiply the two numbers.");
System.out.println("Enter 4 to
divide the first number by the second number.");
choice=input.nextInt();
switch(choice) {
case 1: System.out.println("Sum of
Two number is: "+add(first,second));
break;
case 2:
System.out.println("Subtraction of Two number is:
"+subtract(first,second));
break;
case 3:
System.out.println("Multiplication of Two number is:
"+multiply(first,second));
break;
case 4:
System.out.println("Division of Two number is:
"+divide(first,second));
break;
default :System.out.println("Wrong
Choice");
break;
}
//input.nextInt();
System.out.println("Enter 'Quit' to
end the program.");
input.nextLine();
quit=input.nextLine();
}
while(!quit.equals("Quit"));
}
public static int add(int first,int second) {
return first+second;
}
public static int subtract(int first,int second) {
return first - second;
}
public static int multiply(int first,int second) {
return first * second;
}
public static int divide(int first,int second) {
return first / second;
}
}
Output:

With this program you are going to design a math practice program for younger users. You...
Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...
A Simple Calculator Summary: Write a console program (character based) to do simple calculations (addition, subtraction, multiplication and division) of two numbers, using your understanding of Java. Description: You need to write a program that will display a menu when it is run. The menu gives five choices of operation: addition, subtraction, multiplication, division, and a last choice to exit the program. It then prompts the user to make a choice of the calculation they want to do. Once the...
Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...
This week we looked at an example math program that would display the answer to a random math problem. Enhance this assignment to prompt the user to enter the solution to the displayed problem. After the user has entered their answer, the program should display a message indicating if the answer is correct or incorrect. If the answer is incorrect, it should display the correct answer. The division section should use Real data types instead of Integer data types. Keep...
Read description carefully. Needs to catch exceptions and still be
able to keep the program going on past the error. Program should
allow user to keep going until he or she quits
Math tutor) Write a program that displays a menu as shown in the sample run. You can enter 1, 2. 3, or 4 for choosing an addition. subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter...
IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...
Create a web page that will help students practice math - Addition, Subtraction, Multiplication and Division. The page should generate and display a math problem using 2 random numbers from 1 to 12. Addition: [1 - 12] + [1 - 12] = [2 - 24]<-Calculated Subtraction: [2 - 24]<-Calculated - [1 - 12] = [1 - 12] Multiplication: [1 - 12] * [1 - 12] = [1 - 144]<-Calculated Division: [1 - 144]<-Calculated / [1 - 12] = [1 -...
In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...
In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...
Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...