Advertisement
BiggestEl

Untitled

Nov 27th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. do {
  2. int monthNumber = generator.nextInt(12) + 1;
  3. System.out.print("\nWhat is the name of the month #"
  4. + monthNumber + "? ");
  5. String response = keyboard.next();
  6. Month m = new Month(monthNumber);
  7. //Below used to test second constructor
  8. System.out.println( m.getName() + " " + m.getNumber());
  9. if ( m.getName() .equals(response) ) {
  10. System.out.println("Correct! Very good!" +
  11. "\nThe correct name is" + " " + m + ".");
  12. } else {
  13. System.out.println("Sorry. Month #" + monthNumber + " is " + m);
  14. }
  15. System.out.print("\nDo you want to do another (y or n)?");
  16. answer = keyboard.next() .charAt(0);
  17. } while (answer == 'y' || answer == 'Y' );
  18. }
  19.  
  20. }
  21.  
  22. Said code produced this output when the answer is correct:
  23.  
  24. February 2
  25. Correct! Very good!
  26. The correct name is February.
  27.  
  28. Output produced when the answer is wrong:
  29.  
  30. November 11
  31. Sorry. Month #11 is November
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement