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

Starting code is given for a class whose objects represent the current date as i

ID: 3605165 • Letter: S

Question

Starting code is given for a class whose objects represent the current date as int month, int day, int year. Complete the instance method public boolean withinRange(GPSDate startDate, GPSDate endDate). It should return true exactly when the date (month,day,year) within the instance (this) is neither earlier than startDate, nor later than endDate. That is, "startDate <= this <= endDate" though this isn't legal Java.

Work on completing this by doing test-driven development, creating JUnit test methods within the JUnit test case GPSDateTest. Complete just enough code so the test succeeds.

Starting Code:

public class GPSDate

{

private int month;

private int day;

private int year;

public GPSDate (int m, int d, int y)

{

  this.month = m;

  this.day = d;

  this.year = y;}

public static void main(String[] args)

{

  

}

}

Explanation / Answer

public boolean withinRange(GPSDate startDate, GPSDate endDate){
if(year> startDate.year && year<endDate.year){
return true;
}else if(year >= startDate.year && year<=endDate.year && month >startDate.month && month <endDate.month){
return true;
}else if(year>= startDate.year && year<=endDate.year && month >=startDate.month && month <=endDate.month && day>= startDate.day && day <= endDate.day){
return true;
}
return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote