adding_drill
Adding Drill
10 Points Possible:
- Make a new class called
Question(remember @author Your Name in a comment) - Make two integer fields called
aandb - Make a constructor that initializes a and b so they have a random number from one to ten
- Make a method called
correctthat has aintparameter returns true if the parameter is the correct sum a+b - Make an overloaded method called
correctthat has aStringparameter returns true if the parameter is the correct sum a+b. UseInteger.parseInt()to convert theStringto anint - Make a method called
toStringthat returns the question “What is a + b?” - Make a main method that creates a instance to
Scanner, andQuestion. (Hints: Useimport java.util.Scanner;before the class declaration, and make a newScannerwith the parameterSystem.inso it gets input from the user at the keyboard). There is a method callednextLinethat will return the user's input as aString. (Here is a link that give examples of making an instance of the Scanner class, and here is the link to the full API .) - Try asking one question and checking if it is correct.
- Try using a
whileloop that keeps asking the question until the question is answered correctly. - Try using a
forloop so you ask 3 different questions. Here is how it might look:
adding_drill.txt · Last modified: 2024/10/02 12:20 by frchris
