Advertisement
BiggestEl

Untitled

Nov 26th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package month;
  2.  
  3. import java.util.*; //Scanner, Random
  4.  
  5. public class MonthTester {
  6. public static void main(String [] args) {
  7. System.out.println("Welcome to the month name game!");
  8. System.out.print("\n I will give you a month number;");
  9. System.out.println(" you should enter its name.");
  10. Scanner keyboard = new Scanner(System.in);
  11. Random generator = new Random();
  12. char answer;
  13. do {
  14. int monthNumber = generator.nextInt(12) + 1;
  15. System.out.print("\nWhat is the name of the month #"
  16. + monthNumber + "? ");
  17. String response = keyboard.next();
  18. Month m = new Month(monthNumber);
  19. if ( m.getName() .equals(response) ) {
  20. System.out.println("Correct! Very good!" +
  21. "\nThe correct name is" + " " + m + ".");
  22. } else {
  23. System.out.println("Sorry. Month #" + monthNumber + " is " + m);
  24. }
  25. System.out.print("\nDo you want to do another (y or n)?");
  26. answer = keyboard.next() .charAt(0);
  27. } while (answer == 'y' || answer == 'Y' );
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement