Question: I have this Java code but I can't get it to work. When I put in any input it outputs: Enter the year: 2018 Enter

I have this Java code but I can't get it to work. When I put in any input it outputs: "Enter the year: 2018 Enter the year: Enter the day of the week of January 1st (0=Sunday, 1=Monday, ... 6=Saturday):" which is incorrect.

Also, the professor sent us all this code here, but I am not sure how to implement it:

public static int printMonth(String month, int startDay, int numDays) { System.out.println(month); int dayOfWeek; for (dayOfWeek=0; dayOfWeek

My Code:

package edu.wit.cs.comp1000;

import java.util.Scanner;

public class PA6a {

static final String E_YEAR = "The year must be positive!";

static final String E_DAY = "The day of January 1st must be between 0 and 6!";

public static boolean isLeapYear(int year) {

return false;

}

public static int printMonth(String month, int startDay, int numDays) {

return 0;

}

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the year: ");

int year = input.nextInt();

System.out.print("Enter the year: Enter the day of the week of January 1st (0=Sunday, 1=Monday, ... 6=Saturday): ");

int dayOfWeek = input.nextInt();

if (year < 0) {

System.out.println(E_YEAR);

System.exit(0);

}

if (dayOfWeek < 0 && dayOfWeek > 6) {

System.out.println(E_DAY);

System.exit(0);

}

for (int k = 1; k <= 12; k++) {

String month = "";

int numOfDays = 0;

switch (k) {

case 1:

month = "January ";

numOfDays = 31;

break;

case 2:

month = "February ";

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)

numOfDays = 29;

else

numOfDays = 28;

break;

case 3:

month = "March ";

numOfDays = 31;

break;

case 4:

month = "April ";

numOfDays = 30;

break;

case 5:

month = "May ";

numOfDays = 31;

break;

case 6:

month = "June ";

numOfDays = 30;

break;

case 7:

month = "July ";

numOfDays = 31;

break;

case 8:

month = "August ";

numOfDays = 31;

break;

case 9:

month = "September ";

numOfDays = 30;

break;

case 10:

month = "October ";

numOfDays = 31;

break;

case 11:

month = "November ";

numOfDays = 30;

break;

case 12:

month = "December ";

numOfDays = 31;

break;

}

System.out.println(month + year);

System.out.println("Sun Mon Tue Wed Thu Fri Sat");

for (int i = 1; i <= dayOfWeek; i++)

System.out.print(" ");

for (int j = 1; j <= numOfDays; j++) {

if (dayOfWeek % 7 == 0 && dayOfWeek != 0)

System.out.println();

System.out.printf("%3d ", j);

dayOfWeek += 1;

}

dayOfWeek %= 7;

System.out.print(" ");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!