Question

To be done in Java OOP Write a program that teaches arithmetic to a young child....

To be done in Java OOP

Write a program that teaches arithmetic to a young child. The program tests addition and subtraction. In Level 1, it tests only addition of whole numbers less than ten whose sum is less than ten. In level 2, it tests addition of arbitrary single digit whole numbers. In level 3, it tests subtraction of single digit whole numbers with a non-negative difference. Generate random problems and get the players' 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 correct answers. Make classes for the test and for each level. Make a superclass Level for the classes Level1, Level2, and Level3 so that common methods, such as checkAnswer() , need only be written once in Level and will be inherited.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package mathTest;

public interface ResultChecker { //interface to calculate result

boolean checkAnswer(int a,int b,int ans);

}

package mathTest;

public class Level1 implements ResultChecker{

@Override

public boolean checkAnswer(int a, int b,int ans) { //for addition check is answer is true or not

return a+b==ans;

}

}

package mathTest;

public class Level2 implements ResultChecker {//implement interface to have this method

@Override

public boolean checkAnswer(int a, int b,int ans) {//for addition check is answer is true or not

return a+b==ans;

}

}

package mathTest;

public class Level3 implements ResultChecker{

@Override

public boolean checkAnswer(int a, int b,int ans) {//for subtraction check is answer is true or not

return a-b==ans;

}

}

package mathTest;

import java.util.Random;

import java.util.Scanner;

public class Tester {

public static void main(String[] args) {

Random r=new Random(); //to generate random number

Scanner sc=new Scanner(System.in);

int score=0;

System.out.println("Level one:");

while(score<5){ //keep in level 1 until player scores 5

Level1 l=new Level1();

int a=r.nextInt(5); //generate a, b which will sum less than 10

int b=r.nextInt(5);

System.out.println("Tell sum of "+a+" "+b);

int ans=sc.nextInt(); //take ans input

if(l.checkAnswer(a, b, ans)){ //if ans is right increase the count

score++;

System.out.println("Correct!!! right answer");

}

else{

System.out.println("Oops!!! wrong answer");

}

}

score=0;

System.out.println("Level two:");

while(score<5){ //keep in level 2 until player scores 5

Level2 l=new Level2();

int a=r.nextInt(9999); //generate a, b with upper limit 999

int b=r.nextInt(9999); //generate a, b with upper limit 999 it can be any limit

System.out.println("Tell sum of "+a+" "+b);

int ans=sc.nextInt();

if(l.checkAnswer(a, b, ans)){

score++; //if ans is right increase the count

System.out.println("Correct!!! right answer");

}

else{

System.out.println("Oops!!! wrong answer");

}

}

score=0;

System.out.println("Level Three:");

while(score<5){ //keep in level 2 until player scores 5

Level3 l=new Level3();

int a=r.nextInt(5); //generate a

int b=r.nextInt(a); //generate b less then a so difference remain positive

System.out.println("Tell difference of "+a+" "+b);

int ans=sc.nextInt();

if(l.checkAnswer(a, b, ans)){

score++; //if ans is right increase the count

System.out.println("Correct!!! right answer");

}

else{

System.out.println("Oops!!! wrong answer");

}

}

}

}

output

Level one:

Tell sum of 1 3

4

Correct!!! right answer

Tell sum of 2 3

5

Correct!!! right answer

Tell sum of 3 3

6

Correct!!! right answer

Tell sum of 4 3

7

Correct!!! right answer

Tell sum of 4 3

7

Correct!!! right answer

Level two:

Tell sum of 1387 7998

654

Oops!!! wrong answer

Tell sum of 4263 5760

10023

Correct!!! right answer

Tell sum of 8041 6375

14416

Correct!!! right answer

Tell sum of 2035 7107

9142

Correct!!! right answer

Tell sum of 7541 7358

14899

Correct!!! right answer

Tell sum of 1769 2307

4076

Correct!!! right answer

Level one:

Tell difference of 2 1

1

Correct!!! right answer

Tell difference of 2 1

1

Correct!!! right answer

Tell difference of 3 0

3

Correct!!! right answer

Tell difference of 4 0

4

Correct!!! right answer

Tell difference of 2 0

2

Correct!!! right answer

Add a comment
Know the answer?
Add Answer to:
To be done in Java OOP Write a program that teaches arithmetic to a young child....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • Write In JAVA: Part 1 The use of computers in education is referred to as computer-assisted...

    Write In JAVA: Part 1 The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use a SecureRandom object to produce two positive one-digit integers (you will need to look up how to do this). The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student’s...

  • EVALUATING GENERAL INFIX EXPRESSIONS INTRODUCTION The notation in which we usually write arithmetic expressions is called infix notation;...

    EVALUATING GENERAL INFIX EXPRESSIONS INTRODUCTION The notation in which we usually write arithmetic expressions is called infix notation; in it, operators are written between their operands: X + Y. Such expressions can be ambiguous; do we add or multiply first in the expression 5 + 3 * 2? Parentheses and rules of precedence and association clarify such ambiguities: multiplication and division take precedence over addition and subtraction, and operators associate from left to right. This project implements and exercises a stack-based algorithm that evaluates...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an...

    Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an interactive program that performs fractional calculations. You need define a class CFrac for a fractional number according to the UML diagram below: CFrac - numerator : int - denominator : int - simplify () : void + CFrac (int = 0, int = 1) + ~CFrac() + add (const CFrac&) const : CFrac + subtract (const CFrac&) const : CFrac + multiply (const CFrac&)...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • Order up:: Write a program that will be used to keep track of orders placed at...

    Order up:: Write a program that will be used to keep track of orders placed at a donut shop. There are two types of items that can be ordered: coffee or donuts. Your program will have a class for each order type, and an abstract superclass. Coffee orders are constructed with the following information: quantity (int) - how many coffees are being ordered size (String) - the size of the coffees (all coffees in the order have the same size)...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as...

    Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as a Constraint Satisfaction Problem, with the following guidelines: 1. Since 3 x 3 puzzles are too trivial for a computer, your program should use 4 x 4 puzzles (also known as Super Sudoku puzzles; see Figure 2 for an example). 2. The program should read a Sudoku puzzle from a text file. The user should be able to browse the file system to select...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT