import java.util.Scanner; // Import Scanner class
public class DayOfYear
{
public static void main(String[] args)
{
final int JAN = 31;
final int FEB;
final int MAR = 31;
final int APR = 30;
final int MAY = 31;
final int JUN = 30;
final int JUL = 31; //Set final values for each month of the year
final int AUG = 31;
final int SEP = 30;
final int OCT = 31;
final int NOV = 30;
final int DEC = 31;
Scanner kb = new Scanner(System.in);
System.out.print("Enter a year: "); //prompt user to input a year value
int year = kb.nextInt();
boolean isLeapYear = true; // set value of the variable to true
if ( year <=1582 ) //first exception: year must be more or equal to 152
{
System.out.println("Error: year value must be a positive integer beyond 1582" + "\n");
}
else if ( ( year % 4 == 0 )&&( year % 100 != 0) || ( year % 400 == 0) ) // if conditions are true then year is a leap year
{
isLeapYear = true ;
}
else //else it's not a leap year
{
isLeapYear = false;
}
System.out.print("Enter a day number in that year: "); //prompt user to enter a day number
int dayNumber = kb.nextInt();
if ( (isLeapYear == true) && (( dayNumber > 366) || ( dayNumber < 0)) ) // if it's a leap year and daynumber higher than 366 or negative, ERROR
{
System.out.print("Error: day number value must be a positive integer more than 0" +
"\n" +" and less or equal to 366 (given that " + year + " is a leap year)" + "\n");
}
else if ( (isLeapYear == false) && (( dayNumber > 365) || ( dayNumber < 0)) ) // if it's not a leap year and daynumber higher than 365 or negative, ERROR
{
System.out.print("Error: day number value must be a positive integer more than 0" +
"\n" +" and less or equal to 365 (given that " + year + " is not a leap year)" + "\n");
}
}
}