Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do {
- int monthNumber = generator.nextInt(12) + 1;
- System.out.print("\nWhat is the name of the month #"
- + monthNumber + "? ");
- String response = keyboard.next();
- Month m = new Month(monthNumber);
- //Below used to test second constructor
- System.out.println( m.getName() + " " + m.getNumber());
- if ( m.getName() .equals(response) ) {
- System.out.println("Correct! Very good!" +
- "\nThe correct name is" + " " + m + ".");
- } else {
- System.out.println("Sorry. Month #" + monthNumber + " is " + m);
- }
- System.out.print("\nDo you want to do another (y or n)?");
- answer = keyboard.next() .charAt(0);
- } while (answer == 'y' || answer == 'Y' );
- }
- }
- Said code produced this output when the answer is correct:
- February 2
- Correct! Very good!
- The correct name is February.
- Output produced when the answer is wrong:
- November 11
- Sorry. Month #11 is November
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement