Make a new class called Question
Make two integer fields called a
and b
Make a constructor that initializes a and b so they have a random number from one to ten
Make a method called correct
that has a int
parameter returns true if the parameter is the correct sum a+b
Make an overloaded method called correct
that has a String
parameter returns true if the parameter is the correct sum a+b. Use Integer.parseInt()
to convert the String
to an int
Make a method called toString
that returns the question “What is a + b?”
Make a main method that creates a instance to Scanner
, and Question
. Use import java.util.Scanner;
before the class declaration
Try asking one question and checking if it is correct.
Try using a while
loop that keeps asking the question until the question is answered correctly.
Try using a for
loop so you ask 3 different questions. Here is how it might look: