4th time uploading this picture. it is readable. please, I can\'t use any more q
ID: 3695114 • Letter: 4
Question
4th time uploading this picture. it is readable. please, I can't use any more questions on this.
Explanation / Answer
############### Date1.java ##########################
public class Date1{
protected int Year;
private int Month;
private int Day;
public Date1(){
Year = 0;
Month = 0;
Day = 0;
}
public Date1(int year, int month, int day) {
Year = year;
Month = month;
Day = day;
}
/**
* @return the year
*/
public int getYear() {
return Year;
}
/**
* @return the month
*/
public int getMonth() {
return Month;
}
/**
* @return the day
*/
public int getDay() {
return Day;
}
/**
* @param year the year to set
*/
public void setYear(int year) {
Year = year;
}
/**
* @param month the month to set
*/
public void setMonth(int month) {
Month = month;
}
/**
* @param day the day to set
*/
public void setDay(int day) {
Day = day;
}
// compare method
public int compareTo(Date1 o) {
if(this.Year < o.Year)
return -1;
else if(this.Year > o.Year)
return 1;
else{
if(this.Month < o.Month)
return -1;
else if(this.Month > o.Month)
return 1;
else{
if(this.Day < o.Day)
return -1;
else if(this.Day > o.Day)
return 1;
else
return 0;
}
}
}
@Override
public boolean equals(Object obj) {
Date1 date1 = (Date1)obj;
if(compareTo(date1) == 0)
return true;
else
return false;
}
public void display(){
System.out.println("Date (yyyy/mm/dd): "+Year+"/"+Month+"/"+Day);
}
}
################# DayOfWeek.java ###################################
public class DayOfWeek extends Date1{
private int DoW;
/**
* @param doW
*/
public DayOfWeek(int Year, int Month, int Day, int doW) {
super(Year,Month, Day);
DoW = doW;
}
/**
* @return the doW
*/
public int getDoW() {
return DoW;
}
/**
* @param doW the doW to set
*/
public void setDoW(int doW) {
DoW = doW;
}
// compare method
public int compareTo(DayOfWeek o) {
if(this.getYear() < o.getYear())
return -1;
else if(this.Year > o.Year)
return 1;
else{
if(this.getMonth() < o.getMonth())
return -1;
else if(this.getMonth() > o.getMonth())
return 1;
else{
if(this.getDay() < o.getDay())
return -1;
else if(this.getDay() > o.getDay())
return 1;
else{
if(this.DoW < o.DoW)
return -1;
else if(this.DoW > o.DoW)
return 1;
else
return 0;
}
}
}
}
@Override
public boolean equals(Object obj) {
DayOfWeek d = (DayOfWeek)obj;
if(this.Year == d.Year &&
this.getMonth() == d.getMonth()&&
this.getDay() == d.getDay() &&
this.DoW == d.DoW)
return true;
else
return false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.