Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package month;
- import java.util.*; //Scanner, Random
- public class MonthTester {
- public static void main(String [] args) {
- System.out.println("Welcome to the month name game!");
- System.out.print("\n I will give you a month number;");
- System.out.println(" you should enter its name.");
- Scanner keyboard = new Scanner(System.in);
- Random generator = new Random();
- char answer;
- 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);
- 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' );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement