Computer science lab
Project 1: Arithmetic Quiz The objective of this assignment is to gain experience writing decision statements and loops. You have just been hired as a teacher’s aide in the WSU School of Math, grade 3. Your students need extra practice with their arithmetic skills, and you have been given the task of writing a computer program that will allow them to practice on their own. The specific requirements of the project are as follows: Display the menu shown below and get the user’s choice. If the user does not enter a valid choice, output an appropriate message and prompt for another choice. Please choose one of the following options for your math quiz: 1. Addition with numbers 110 2. Addition with numbers 1100 3. Subtraction with numbers 110 4. Subtraction with numbers 1100 5. Multiplication with numbers 110 6. Exit the program If the user chooses one of the first five menu options, display five problems of the requested type to the user. For example, if the user chooses option 1, your program should display five addition problems, one at a time, using randomly randomly generated operands between 1 and 10. After each problem, your program should read the user’s answer and display an appropriate error message: either “That is the correct answer!” or “Sorry, that is incorrect. The correct answer is X”, where X is the correct answer to the arithmetic problem. If the user chooses the last menu option, the program should output the number of problems correct, the number of problems tried, and the percentage of problems correct to 2 decimal places before terminating. Hint: You can use the following formula to generate random numbers: (int)(lowerBound + Math.random() * (upperBound – lowerBound + 1)) You may use literals in place of the upper and lower bounds. For instance, to display values between 1 and 10 (inclusive on both ends), the formula would look like this: (int)(1 + Math.random() * 10)
A sample run of this program is shown below: Welcome to the Wright State School of Math!
Please choose one of the following options for your math quiz: 1. Addition with numbers 110 2. Addition with numbers 1100 3. Subtraction with numbers 110 4. Subtraction with numbers 1100 5. Multiplication with numbers 110 6. Exit the program 2 Enter the answer to the following problem: 12 + 37 49 That is the correct answer! Enter the answer to the following problem: 47 + 90 137 That is the correct answer! Enter the answer to the following problem: 77 + 67 34 Sorry, that is incorrect. The correct answer is 144 Enter the answer to the following problem: 42 + 14 55 Sorry, that is incorrect. The correct answer is 56 Enter the answer to the following problem: 40 + 46 86 That is the correct answer! Please choose one of the following options for your math quiz: 1. Addition with numbers 110 2. Addition with numbers 1100 3. Subtraction with numbers 110 4. Subtraction with numbers 1100 5. Multiplication with numbers 110 6. Exit the program 8 Valid choices are 16; please reenter 7 Valid choices are 16; please reenter 5 Enter the answer to the following problem: 6*3 18 That is the correct answer!
Enter the answer to the following problem: 4*2 8 That is the correct answer! Enter the answer to the following problem: 8*1 8 That is the correct answer! Enter the answer to the following problem: 6*6 12 Sorry, that is incorrect. The correct answer is 36 Enter the answer to the following problem: 3*6 18 That is the correct answer! Please choose one of the following options for your math quiz: 1. Addition with numbers 110 2. Addition with numbers 1100 3. Subtraction with numbers 110 4. Subtraction with numbers 1100 5. Multiplication with numbers 110 6. Exit the program
3
Enter the answer to the following problem: 83 5 That is the correct answer! Enter the answer to the following problem: 10 1 9 That is the correct answer! Enter the answer to the following problem: 32 1 That is the correct answer! Enter the answer to the following problem: 95 4 That is the correct answer! Enter the answer to the following problem: 72 5 That is the correct answer! Please choose one of the following options for your math quiz: 1. Addition with numbers 110 2. Addition with numbers 1100 3. Subtraction with numbers 110
4. Subtraction with numbers 1100 5. Multiplication with numbers 110 6. Exit the program
6
You got 12 problems correct out of 15 problems attempted. That is
80.00 percent correct. Goodbye!
Rubric (each item is worth one point):
• Displays the menu and gets the user's choice
• Performs the requested action for all menu items (e.g. if the user chooses option 5, then five multiplication problems are displayed)
• Recognizes invalid user menu choices (e.g. “7” when the menu only contains
six items) and prompts the user to choose a different option
• Gets the user's answers to the arithmetic problems and displays the appropriate message in response (i.e. correct or incorrect)
• Displays the requested statistics (i.e. number of questions tried and percent
correct) before terminating.
• The program is well design and follows the style guidelines