All pastes #1822745 Raw Edit

Miscellany

public text v1 · immutable
#1822745 ·published 2010-03-04 15:51 UTC
rendered paste body
import java.util.Scanner;

/**
	A class that that prompts the user for a year in the Gregorian calendar and prints a message to indicate whether or not it is a leap year.
*/
public class GregorianYearApp
{
	/**
		Contains the main method.
		@param args not used
	*/
	public static void main(String[] args)
	{
		// Constructs a new GregorianYear object with the year set to zero.
		GregorianYear myYear = new GregorianYear();
		
		// Contructs a new Scanner object.
		Scanner in = new Scanner(System.in);
		
		// Gets the year.
		System.out.print("Enter a year in the Gregorian calendar: "); // Prompts the user for a year in the Gregorian calendar.
		int number = in.nextInt(); // Reads the integer number entered by the user.
		
		// Sets the year to number if the year entered by the user is a year in the Gregorian calendar. Otherwise, it prints an error message.
		if (number >= 1582)
		{
			myYear.setYear(number); // Sets the year to number.
			if (myYear.isLeapYear()) // Determines whether or not the year is a leap year and prints the results.
			{
				System.out.println("The year that you have entered is a leap year."); // Prints that the year is a leap year.
			}
			else
			{
				System.out.println("The year that you have entered is not a leap year."); // Prints that the year is not a leap year.
			}
		}		
		else
		{
			System.out.println("ERROR: The year that you have entered is not a year in the Gregorian calendar.");
		}
	}
}