Question: 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

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:

With this program you are going to design a math practice program

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.

Hint:

This code will help to skip over added words.

while(!scanner.hasNextInt()){ scanner.next(); }

Starter Code:

import java.util.Scanner;

public class MathTeacher {

public static int addNumbers(int n1, int n2){

} public static int subtractNumbers(int n1, int n2){

} public static int multiplyNumbers(int n1, int n2){

} public static int divideNumbers(int n1, int n2){

} /** * @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 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.");

} }

run: Welcome to *Mental Math Practice where you can test your addition, subtraction, multiplication, and division. Enter two integers: asdf 1 2 Enter 1 to add the two numbers. Enter 2 to subtract the second number from the first number. Enter 3 to multiply the two numbers. Enter 4 to divide the first number by the second number. 1 3 Enter 'Quit' to end the program. Enter two integers: 1 2 Enter 1 to add the two numbers. Enter 2 to subtract the second number from the first number. Enter 3 to multiply the two numbers. Enter 4 to divide the first number by the second number. 2 -1 Enter 'Quit' to end the program. Quit BUILD SUCCESSFUL (total time: 22 seconds)

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 Databases Questions!