Programming in Java Write a program that will help a student
Programming in Java:
Write a program that will help a student practice basic math (addition, subtraction, multiplication, and division).
Display a menu the student can select from, including exit program.
The student will make a selection then answer as many as they want until inputting something like.. menu
When the student is done and returns to the main menu, they can select another type of problem, etc... etc...
When the student is done and inputs exit from the main menu, their results will be displayed
EXAMPLE:
Addition: 3 correct 2 incorrect
Subtraction: 100 correct 0 incorrect
Division: 1 correct 21 incorrect
^^^^^^^^^^^example for multiplication not displayed if user didn\'t answer any.....
If (multCorrect>= 1 || multIncorrect>= 1 )
{
System.out.println(\"Multiplication:\\t\" +multCorrect+ \" correct \" +multIncorrect+ \"incorrect\");
}
something like that, or any other statement(s) you deem appropriate.
REQUIREMENTS :
Use Ifs, loops, switchs (basic error checks)
Randomize numbers 0-10
User defined classes (multiple classes)
HINTS:
Create multiple classes and methods to keep Main program short.
Use methods in the classes other than the normal gets/sets
Randomize 0-10 for numbers in the math problems.
Use fields to track the correct and incorrect counts.
Break everything down to smaller simpler methods and code
Try not to over complicate
Solution
import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
float a, b, res;
char choice, ch;
Scanner scan = new Scanner(System.in);
do
{
System.out.print(\"1. Addition\ \");
System.out.print(\"2. Subtraction\ \");
System.out.print(\"3. Multiplication\ \");
System.out.print(\"4. Division\ \");
System.out.print(\"5. Exit\ \ \");
System.out.print(\"Enter Your Choice : \");
choice = scan.next().charAt(0);
switch(choice)
{
case \'1\' : System.out.print(\"Enter Two Number : \");
a = scan.nextFloat();
b = scan.nextFloat();
res = a + b;
System.out.print(\"Result = \" + res);
break;
case \'2\' : System.out.print(\"Enter Two Number : \");
a = scan.nextFloat();
b = scan.nextFloat();
res = a - b;
System.out.print(\"Result = \" + res);
break;
case \'3\' : System.out.print(\"Enter Two Number : \");
a = scan.nextFloat();
b = scan.nextFloat();
res = a * b;
System.out.print(\"Result = \" + res);
break;
case \'4\' : System.out.print(\"Enter Two Number : \");
a = scan.nextFloat();
b = scan.nextFloat();
res = a / b;
System.out.print(\"Result = \" + res);
break;
case \'5\' : System.exit(0);
break;
default : System.out.print(\"Wrong Choice!!!\");
break;
}
System.out.print(\"\ ---------------------------------------\ \");
}while(choice != 5);
}
}


