Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.Scanner; /** * Days determines the number of days between two d

ID: 3641143 • Letter: I

Question

import java.util.Scanner;

/**
* Days determines the number of days between two dates.
* @author X
*/
public class Days {
public static void main(String[] args) {
String start = "02/23/2011"; // replace with input
String end = "04/15/2011"; // replace with input
System.out.printf("Days between %s and %s are %d. ", start, end,
daysBetweenDates(start, end));
}

/**
* isLeapYear determines whether a year is a leap year or not
* @param year (int) Years since recognized beginning of C.E.
* @return (boolean) true if year divisible by 4 (but not 100)
*/
public static boolean isLeapYear(int year) {
System.out.println("in isLeapYear");
return false;
}

/**
* daysInMonth looks up the number of days in the specified month
* @param month (int) a number between 1 and 12 indicating the desired month
* @param year (int) the year is only meaningful for February (2)
* @return (int) the last day of month/year (or 0 if invalid month provided)
*/
public static int daysInMonth(int month, int year) {
System.out.println("calculating days in a month");
return 30;
}

/**
* daysIntoYear translates a date (month, day, year) into a single number
* representing the days since 12/31/(year-1).
* @param month (int) 1-12, where 1 is January and 12 is December
* @param day (int) 1-31, or actually up to daysInMonth
* @param year (int) years since start of C.E.
* @return (int) number of days between 12/31/(year-1) and (month)/(day)/(year)
*/
public static int daysIntoYear(int month, int day, int year) {
System.out.println("calculating days into year");
return 1;
}

/**
* daysBetweenDates calculates number of days between two dates.
* @param start (String) starting date
* @param end (String) ending date, presumably later than start
* @return (int) days between start date and end date
*/
public static int daysBetweenDates(String start, String end) {
int days = 0;

System.out.println("calculating daysBetweenDates");
return days;
}
}

Explanation / Answer

public static boolean isLeapYear(int year)
{
boolean isLeap = year%4 == 0 && ( year % 100 != 0 || year %400==0 );

if(isLeap)
{
System.out.print("The year " + year + " is a leap year ");
return true;
}
else
{
System.out.print("The year " + year + " isn't a leap year ");
return true;
}

}

/**
* daysInMonth looks up the number of days in the specified month
* @param month (int) a number between 1 and 12 indicating the desired month
* @param year (int) the year is only meaningful for February (2)
* @return (int) the last day of month/year (or 0 if invalid month provided)
*/
public static int daysInMonth(int month, int year)
{
System.out.println("calculating days in a month");
if(month > 0 && month < 13)
{
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
System.out.println("The month " + month + " has 31 days");
return 31;

}
else if( month == 4 || month == 6 || month == 9 || month == 11)
{
System.out.println("The month " + month + " has 30 days");
return 30;
}
else if(isLeapYear(year) && month == 2)
{
System.out.println("The month " + month + " has 29 days");
return 29;
}
else
{
System.out.println("The month " + month + " has 28 days");
return 28;
}
}
else
{
System.out.println("The month "+ month +"is not valid");
return -1;
}
}