Hi - it's the learning student again :) Our new assignment is to create a program to determine leap year, month and day information. So basically you enter a year and the program says if it is a leap year. Then you enter a month and the program determines if that month is part of that leap year. And then you enter a day and determine if that day is part of that leap month that is part of that leap year. I have written a program to determine if it is a leap year and to determine that if the month is february it is a leap month, but not if the month is part of that leap year - so I am missing a step. And so it goes for the leap day - I have created the program to read that the 29th is a leap day but not exculsively to the month of february that falls in the leap year. Make sense? Here is my code so far:
Here are details of the assignment:
1.Prompt the user for a year using GUI dialogue window.
a.Remember to give the user clear direction on input requirements.
i.E.g. "Please enter month as integer 1-12:"
2.Prompt the user for the month using GUI dialogue window.
a.Remember to give the user clear direction on input requirements.
b.** Please note: month must be input as a string, and then converted to an integer for the case statement below. This may require 2 case statements.
3.Prompt the user for a day in the month.
a.This must return a message to the user if the month doesn’t include that day.
b.i.e. entering 30 in a February month should tell the user it is an invalid day and stop execution.
4.Check to see if the year is a leap year.
5.Check to see if the month is a leap month.
6.Check to see if the day is a leap day.
7.Display a user friendly back to the consumer indicating:
a.Year entered & If it is a leap year
b.Month entered & if it is a leap month.
c.The number of days in the month (e.g. January has 31 days, whereas February has 28 unless it is a leap year.
d.The day of the month entered & whether or not is a Leap day.
e.Output can be in three different dialogue windows, or just 1 if desired.
And here is my code - I am not sure what to do next. It is running and compiling without any errors right now but I know I am missing some steps. Any help or advice in what steps to take next would be appreciated!
import javax.swing.JOptionPane;
public class Leap_Year {
public static void main (String[] args) {
//Enter a year
String enterYearString = JOptionPane.showInputDialog("Enter a year: ");
//Convert year to an integer
int enterYear = Integer.parseInt(enterYearString);
// Check if year is a leap year
boolean isLeapYear =
(enterYear % 4 == 0 && enterYear % 100 != 0) || (enterYear % 400 == 0);
//Enter a month
String enterMonthString = JOptionPane.showInputDialog("Enter a month as an integer, e.g. 1-12: ");
//Convert month to an integer
int enterMonth = Integer.parseInt(enterMonthString);
//Check if month is a leap year
boolean isLeapMonth =
(enterMonth == 2);
//Enter a day
String enterDayString = JOptionPane.showInputDialog("Enter a Day as an integer, e.g. 1-31: ");
//Convert day to an integer
int enterDay = Integer.parseInt(enterDayString);
//Check if day is a leap day
boolean isLeapDay =
(enterDay == 29);
//Display the result
String output = "The year " + enterYear + " is a leap year is: " + isLeapYear +
"\nThe month " + enterMonth + " is a leap month is: " + isLeapMonth +
"\nThe day " + enterDay + " is a leap day is: " + isLeapDay;
JOptionPane.showMessageDialog(null,output);
}
}