Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that teaches arithmetic to a young child. The program tests addi

ID: 3660273 • Letter: W

Question

Write a program that teaches arithmetic to a young child. The program tests addition and subtraction. In level 1 it tests only addition of numbers less than 10 whose sum is less than 10. In level 2 it tests addition of arbitrary one-digit numbers. In level 3 it tests subtraction of one-digit numbers with a non negative difference. Generate random problems and get the player input. The player gets up to two tries per problem. Advance from one level to the next when the player has achieved a score of five points

Explanation / Answer

Please find the below program. It has 3 method, the inputs are tested for one digit number , if not the program is exited. Method 1 test for additional check that is sum is less than 10 and method 3 test for difference to be non negative. Appropriate messages are shown and the points added at each stage and program advances it levels. import java.util.Scanner; public class ArithmeticGame { String player1; int player1Points; float no1; float no2; public String getPlayer1() { return player1; } public void setPlayer1(String player1) { this.player1 = player1; } public int getPlayer1Points() { return player1Points; } public void setPlayer1Points(int player1Points) { this.player1Points = player1Points; } public float getNo1() { return no1; } public void setNo1(int no1) { this.no1 = no1; } public float getNo2() { return no2; } public void setNo2(int no2) { this.no2 = no2; } void addarbitary1DigitSumLess10() { if ((no1 + no2) / 10 >= 1) { System.out.println((no1 + no2) + " is not a one digit number"); return; } player1Points = 5; System.out .println("Congrats you are advancing to next level with points " + player1Points); return; } void addarbitary1DigitNos() { player1Points = player1Points + 5; System.out .println("Congrats you are advancing to next level with points " + player1Points); return; } void subarbitary1DigitNonNegativeDiff() { if ((no1 - no2) < 0) { System.out.println((no1 - no2) + " is negative"); return; } player1Points = player1Points + 5; System.out.println("Congrats you won all levels and your points " + player1Points); return; } public static void main(String[] args) { System.out.println("Welcome to Arithemtic Game"); Scanner sc = new Scanner(System.in); ArithmeticGame game = new ArithmeticGame(); System.out.println("Enter No 1"); game.setNo1(sc.nextInt()); if (game.getNo1() / 10.0 >= 1) { System.out.println(game.getNo1() + " is not a one digit number"); return; } System.out.println("Enter No 2"); game.setNo2(sc.nextInt()); if (game.getNo2() / 10.0 >= 1) { System.out.println(game.getNo2() + " is not a one digit number"); return; } game.addarbitary1DigitSumLess10(); System.out.println("Enter No 1"); game.setNo1(sc.nextInt()); if (game.getNo1() / 10.0 >= 1) { System.out.println(game.getNo1() + " is not a one digit number"); return; } System.out.println("Enter No 2"); game.setNo2(sc.nextInt()); if (game.getNo2() / 10.0 >= 1) { System.out.println(game.getNo2() + " is not a one digit number"); return; } game.addarbitary1DigitNos(); System.out.println("Enter No 1"); game.setNo1(sc.nextInt()); if (game.getNo1() / 10.0 >= 1) { System.out.println(game.getNo1() + " is not a one digit number"); return; } System.out.println("Enter No 2"); game.setNo2(sc.nextInt()); if (game.getNo2() / 10.0 >= 1) { System.out.println(game.getNo2() + " is not a one digit number"); return; } game.subarbitary1DigitNonNegativeDiff(); } } Output 1: Welcome to Arithemtic Game Enter No 1 1 Enter No 2 2 Congrats you are advancing to next level with points 5 Enter No 1 3 Enter No 2 4 Congrats you are advancing to next level with points 10 Enter No 1 6 Enter No 2 5 Congrats you won all levels and your points 15 Output 2: Welcome to Arithemtic Game Enter No 1 4 Enter No 2 3 Congrats you are advancing to next level with points 5 Enter No 1 2 Enter No 2 7 Congrats you are advancing to next level with points 10 Enter No 1 4 Enter No 2 5 -1.0 is negative Hope it helps!
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote