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

You have been hired by the UCMerced Dorm Life Council to prepare a program which

ID: 3695865 • Letter: Y

Question

You have been hired by the UCMerced Dorm Life Council to prepare a program which measures compatibility between potential roommates. You are given a file with the list of students. For each student, you are given their name, gender and birthday.   You will also have their preference for quiet time, music, reading and chatting. Using this information, you can then determine the compatibility between two people for rooming together, according to a formula developed by the Dorm Life Council. You will need to create four classes in order to do this project: Match.java, Student.java, Date.java and Preference.java.

The class named Date should have the following instance variables:

• year: of type int in the range 1900-3000

• month: in the range 1 to 12 (January is 1)

• day: in the range 1 to 31 AND appropriate to the month. (can assume February is always 28 days)

The class Date should have at least the following methods:

• a constructor, which sets the instance variables to their appropriate input parameters (3 inputs)

• Accessor methods for each of the 3 instance variables

• compare(Date dt) method that returns the difference between oneself and the Date input parameter, dt.

o Use dayOfYear() to calculate the difference between month/day then add 365*years to it. Finally divide the total number of days differential by 30 to approximate the # of months as a difference. If the difference is higher than 60 then should only return 60 as a max value.

public int dayOfYear() {

int totalDays = 0;

switch (month) {

case 12: totalDays += 30;

case 11: totalDays += 31;

case 10: totalDays += 30;

case 9 : totalDays += 31;

case 8 : totalDays += 31;

case 7 : totalDays += 30;

case 6 : totalDays += 31;

case 5 : totalDays += 30;

case 4 : totalDays += 31;

case 3 : totalDays += 28;

case 2 : totalDays += 31; }

totalDays += day;

return totalDays;

}

}

Explanation / Answer

import java.util.GregorianCalendar;
class Date{
private int year;
private int month;
private int day;
Date(int year,int month,int day){
this.year=year;
this.month=month;
this.day=day;
}
public int getYear(){
return year;
}
public int getMonth(){
return month;
}
public int getDay(){
return day;
}
public void setYear(int year){
this.year=year;
}
public void setMonth(int month){
this.month=month;
}
public void setDay(int day){
this.day=day;
}
public long compare(Date dt){
java.util.Date d1 = new GregorianCalendar(this.getYear(), this.getMonth(), this.getDay(), 00, 00).getTime();
java.util.Date d2 = new GregorianCalendar(dt.getYear(), dt.getMonth(), dt.getDay(), 00, 00).getTime();
long diff = Math.abs(d2.getTime() - d1.getTime());
return (diff / (1000 * 60 * 60 * 24));
}
  
public int dayOfYear() {
int totalDays = 0;
switch (month) {
case 12: totalDays += 30;
case 11: totalDays += 31;
case 10: totalDays += 30;
case 9 : totalDays += 31;
case 8 : totalDays += 31;
case 7 : totalDays += 30;
case 6 : totalDays += 31;
case 5 : totalDays += 30;
case 4 : totalDays += 31;
case 3 : totalDays += 28;
case 2 : totalDays += 31;
}
totalDays += day;
return totalDays;
}

  
public static void main(String[] args){
Date d1=new Date(2016,01,01);
Date d2=new Date(2015,01,01);
d1.compare(d2);
}
}

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