User Tools

Site Tools


adding_drill

Adding Drill

10 Points Possible:

  1. Make a new class called Question (remember @author Your Name in a comment)
  2. Make two integer fields called a and b
  3. Make a constructor that initializes a and b so they have a random number from one to ten
  4. Make a method called correct that has a int parameter returns true if the parameter is the correct sum a+b
  5. 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
  6. Make a method called toString that returns the question “What is a + b?”
  7. Make a main method that creates a instance to Scanner, and Question. (Hints: Use import java.util.Scanner; before the class declaration, and make a new Scanner with the parameter System.in so it gets input from the user at the keyboard). There is a method called nextLine that will return the user's input as a String. (Here is a link that give examples of making an instance of the Scanner class, and here is the link to the full API .)
  8. Try asking one question and checking if it is correct.
  9. Try using a while loop that keeps asking the question until the question is answered correctly.
  10. Try using a for loop so you ask 3 different questions. Here is how it might look:

adding_drill.txt · Last modified: 2024/10/02 12:20 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki