JAVA Write a program to display a menu. Each menu item will represent one of the
ID: 3714076 • Letter: J
Question
JAVA
Write a program to display a menu. Each menu item will represent one of the problem statements below. You will be implementing them with one or more methods, feel free to reuse previously written code Extra credit point if you write your code organized in two separate classes with some of your methods calling other methods from the other class. That is similar to the concept of using methods in Math class such as Math.sart or Math.random Problem Statement 1) Write a method that calculates and finds out i. The day of the week the user's date of birth falls on (Sun 1, Mon 2, Tues 3, ..). Then your method calls another method to calculate and find out whether the year of the same user's birth was a leap year or not. If the user's DoB was May 13, 1998 I expect your code will display The year 1998 is a leap year? True or False: False May 13, 1998 fell on day numbe Extra credit point if your method can distinguish a future dates from a dates in the past and adjust the message accordingly. If the user's DoB was May 13, 1998 I expect your code will display The year 2020 will be a leap year? True or False: True May 13, 2020 will fall on day number 4 Extra credit point if your method can call another method to find out what day Easter Sunday feel/will falls for the same year given above. The formula for calculating Easter Sunday can be found on http://www.whydomath.org/Reading Room Material/ian stewart/2000 03.htExplanation / Answer
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class MyClass {
public static boolean isLeapYear(int year) {
if (year % 4 != 0) {
return false;
} else if (year % 400 == 0) {
return true;
} else if (year % 100 == 0) {
return false;
} else {
return true;
}
}
public static void printDayOfWeek(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
System.out.print("The year " + year + " is a leap year? True or False: ");
if (isLeapYear(year)) {
System.out.println("True");
} else {
System.out.println("False");
}
SimpleDateFormat simpleDateformat = new SimpleDateFormat("MMM dd, YYYY");
System.out.println(simpleDateformat.format(date) + " fell on day number "+ calendar.get(Calendar.DAY_OF_WEEK));
}
public static void main(String[] args) {
printDayOfWeek(new Date());
}
}
Sample run
The year 2018 is a leap year? True or False: False
Apr 23, 2018 fell on day number 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.