Question
I need help with this Eclipse IDE Java program. I'm making a calendar with all 12 months and their days from 1780 to 2040. I
I need help with this Eclipse IDE Java program. I'm making a calendar with all 12 months and their days from 1780 to 2040. I got most of it complete, but any months that have six weeks in them like 2000 January it doesn't show all six weeks. I want to know what needs to fix it. Here is the program:
import java.util.Scanner; public class MyCalendar {
public static void main(String[] args) { Scanner input = new Scanner(System.in); // Stage 1 System.out.print("Enter year: "); int year = input.nextInt(); while (year < 1780 || year > 2040) { System.out.print("Enter year: "); year = input.nextInt(); } // Stage 2 int d = (int)(28 + year % 100 + Math.floor((year % 100 - 1) / 4.0) + Math.floor(year / 400.0) - 2 * Math.floor(year / 100.0)) % 7; // Stage 3.0 int days = 0; String month_name = ""; for (int month = 1; month <= 12; month++) { // Stage 3.1 switch (month) { case 1: month_name = "January"; days = 31; break; case 2: month_name = "February"; days = 28; break; case 3: month_name = "March"; days = 31; break; case 4: month_name = "April"; days = 30; break; case 5: month_name = "May"; days = 31; break; case 6: month_name = "June"; days = 30; break; case 7: month_name = "July"; days = 31; break; case 8: month_name = "August"; days = 31; break; case 9: month_name = "September"; days = 30; break; case 10:month_name = "October"; days = 31; break; case 11:month_name = "November"; days = 30; break; case 12:month_name = "December"; days = 31; break; } System.out.println("--------------------------------------"); System.out.println("\t " + month_name + " " + year); // Stage 3.2 System.out.println(" Sun Mon Tue Wed Thu Fri Sat"); // Stage 3.3 if (month == 2 && (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))) days += 1; int a = 0; while (a < days + d) { if (a - d < 0) System.out.printf("%5c", ' '); else System.out.printf("%5d", a - d + 1); if ((a + 1) % 7 == 0) System.out.println(); a++; } System.out.println(); d = (days + d) % 7; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started