For this assignment you will need to design and construct a basic math program w
ID: 3534600 • Letter: F
Question
For this assignment you will need to design and construct a basic math program which targets elementary school children. Your program must adhere
to the following steps and requirements:
1. (5 pts) A user interface with options similar to the following:
a. Learn about how to use the program
b. Enter your initials (3 individual characters...)
c. Difficulty selection
d. Start a new sequence of problems
e. Save and Quit
2. (25 pts - 5 pt/level) Generate mathematical problems based on the difficulty level selected. You must implement the following five levels of difficulty:
a. Level 1 - Easy: Includes addition and subtraction problems, with positive single digit operands and up to three terms only (i.e. d1 + d2 - d3 = )
b. Level 2 - Fair: Includes multiplication problems, with positive single digit operands and up to two terms only (i.e. d1 x d2 = )
c. Level 3 - Intermediate: Includes division problems, with positive single digit operands and up to two terms only (i.e. d1 / d2 = ); Note: results should be shown in the
form Num R Remainder, i.e. if the problem is 5 / 3, then the answer should be provided as 1 R 2.
d. Level 4 - Hard: Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative single digit operands
and up to three terms only (i.e. d1 + -d2 / d3 = ); Hint: you may have to first find a common denominator.
e. Level 5 - Impossible: Includes a mix of addition, subtraction, multiplication, and division problems, with positive and negative two and three digit operands
and up to four terms only (i.e. dd1 + -ddd2 x ddd3 / dd4 = ); Hint: you may have to first find a common denominator.
3. (5 pts) Allow the user to enter an answer corresponding to a generated math problem
4. (10 pts) Evaluate the answer provided by the user. The user gets a certain number of points for correct answers and loses points for incorrect answers. The number of points
should directly relate to the difficulty of the problem.
5. (10 pts) Each level must generate a sequence of ten problems
6. (10 pts) Within each level, problems should become a little more difficult as the user enters correct answers
7. (10 pts) Once the user quits the program, output the user's initials and total score to a file
Explanation / Answer
import java.util.Scanner; public class MathTutor { Scanner input = new Scanner(System.in); int numQuestions; int choice; int numCorrect; public MathTutor (){ numQuestions = choice = numCorrect = 0; } public int getNumQuestions(){ { System.out.print("How many questions? "); numQuestions = input.nextInt(); if (numQuestions < 1) { System.out.println("Invalid - must ask at least 1 question"); } }return numQuestions;} public int getQuestionType(){ while (choice < 1 || choice > 4) { System.out.println("Please select the type of questions you would like"); System.out.println("1) Addition"); System.out.println("2) Subtraction"); System.out.println("3) Multiplication"); System.out.println("4) Division"); System.out.print("Type: "); choice = input.nextInt(); if (choice < 1 || choice > 4) { System.out.println("Choice must be in the range 1-4"); } }return choice;} public void askQuestions() { for (int i = 0; i < numQuestions; i++) { int num1 = genRandomNum(1); int num2 = genRandomNum(1); int sign = choice; if (sign == 5) { sign = (int)(Math.random() * 4 + 1); } switch(sign) { case 1: addition(num1, num2); break; case 2: subtraction(num1, num2); break; case 3: multiplication(num1, num2); break; case 4: division(num1, num2); break; default: System.out.println("Error"); System.exit(1); } } } public int genRandomNum(int difficulty) { if (difficulty == 1) { return (int)(Math.random() * 10); } else { return (int)(Math.random() * 100); } } public void addition(int num1, int num2) { System.out.print("What is " + num1 + " + " + num2 + "? "); int answer = input.nextInt(); if (num1 + num2 == answer) { System.out.println("Correct"); numCorrect++; } else { System.out.println("Incorrect -> " + num1 + " + " + num2 + " = " + num1+num2); } } public void subtraction(int num1, int num2) { System.out.print("What is " + num1 + " - " + num2 + "? "); int answer = input.nextInt(); if (num1 - num2 == answer) { System.out.println("Correct"); numCorrect++; } else { System.out.println("Incorrect -> " + num1 + " - " + num2 + " = " + num1+num2); } } public void multiplication(int num1, int num2) { System.out.print("What is " + num1 + " * " + num2 + "? "); int answer = input.nextInt(); if (num1 * num2 == answer) { System.out.println("Correct"); numCorrect++; } else { System.out.println("Incorrect -> " + num1 + " * " + num2 + " = " + num1+num2); } } public void division(int num1, int num2) { boolean quotientCorrect = false; boolean remainderCorrect = false; System.out.print("What is the quotient of " + num1 + " / " + num2 + "? "); int answer = input.nextInt(); System.out.print("What is the remainder of " + num1 + " / " + num2 + "? "); int remainder = input.nextInt(); if (num1 / num2 == answer) { quotientCorrect = true; } if (num1 % num2 == remainder) { remainderCorrect = true; } if (quotientCorrect && remainderCorrect) { System.out.println("Correct"); numCorrect++; } else { System.out.println("Incorrect -> " + num1 + " / " + num2 + " = " + num1/num2 + "r" + num1%num2); } } public void printReport(long totalTime) { System.out.println("Number of correct responses: " + numCorrect + "/" + numQuestions); double percent = numCorrect/numQuestions; System.out.println("Your percentage: " + percent + "%"); System.out.println("Total time taken: " + totalTime/1000 + "s"); System.out.println("Average time per question: " + (totalTime/numQuestions)/1000 + "s"); } }Please rate with 5 stars :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.