Hello. I have this question:
"Amend the subclass of Holiday called Premier with an overridden equals method. Test this method in an orchestrating
class with objects of Premier that contain the same data values and with objects that
contain different data values."
I have searched high and low for a good explanation of overriding and how to achieve it but it refuses to click for me. Could someone please (using my code) explain how I go about achieving the answer to the question. Or point me in the right direction.
So far I have as follows:
Holiday.java
package Holiday;
//<---------------------------------------------------------------------------------------------------------------------------------------------------------
public class Holiday {
static String startDate;
static String endDate;
static String place;
static String price;
static String hotelGrade;
static String hotelName;
static String resortName;
//<---------------------------------------------------------------------------------------------------------------------------------------------------------
public Holiday(String startDate2, String endDate2, String place2, String price2){
startDate = startDate2;
endDate = endDate2;
place = place2;
price = price2;
}
//<---------------------------------------------------------------------------------------------------------------------------------------------------------
public static void setStartDate(String sDate){
startDate = sDate;
}
public static String getStartDate(){
return startDate;
}
public static void setEndDate(String eDate){
endDate = eDate;
}
public static String getEndDate(){
return endDate;
}
public static void setPlace(String pla){
place = pla;
}
public static String getPlace(){
return place;
}
public static void setPrice(String pri){
price = pri;
}
public static String getPrice(){
return price;
}
//<---------------------------------------------------------------------------------------------------------------------------------------------------------
public static void main(String[] args){
// HolidayOrch.setHol(); // UNCOMMENT FOR QUESTION 2
//
//
// System.out.println("Holiday One:\n");
// System.out.println("The Start Date: " + getStartDate());
// System.out.println("The End Date: " + getEndDate());
// System.out.println("The Location: " + getPlace());
// System.out.println("The Price: " + getPrice()+"\n" + "\n");
//
//
// HolidayOrch.setHol2();
//
// System.out.println("Holiday Two:\n");
// System.out.println("The Start Date: " + getStartDate());
// System.out.println("The End Date: " + getEndDate());
// System.out.println("The Location: " + getPlace());
// System.out.println("The Price: " + getPrice());
HolidayOrch.setPremierAndHol();
System.out.println("Holiday & Premier Information:\n");
System.out.println("The Start Date: " + getStartDate());
System.out.println("The End Date: " + getEndDate());
System.out.println("The Location: " + getPlace());
System.out.println("The Price: " + getPrice());
System.out.println("The Hotel Grade: " + Premier.getHotelGrade());
System.out.println("The Hotel Name: " + Premier.getHotelName());
System.out.println("The Resort Name: " + Premier.getResortName());
}
//<---------------------------------------------------------------------------------------------------------------------------------------------------------
}
Premier.java:
package Holiday;
public class Premier extends Holiday{
//<--------------------------------------------------------------------------------------------------------------------------------
public Premier(String hotelGrade2, String hotelName2, String resortName2, String startDate2, String endDate2, String place2, String price2) {
super(startDate2, endDate2, place2, price2);
hotelGrade = hotelGrade2;
hotelName = hotelName2;
resortName = resortName2;
}
public static void setHotelGrade(String hotelGrade2){
hotelGrade = hotelGrade2;
}
public static String getHotelGrade(){
return hotelGrade;
}
public static void setHotelName(String hotelName2){
hotelName = hotelName2;
}
public static String getHotelName(){
return hotelName;
}
public static void setResortName(String resortName2){
resortName = resortName2;
}
public static String getResortName(){
return resortName;
}
//<--------------------------------------------------------------------------------------------------------------------------------
}
HolidayOrch.java
package Holiday;
public class HolidayOrch {
//<--------------------------------------------------------------------------------------------------------------------------------
public static void main(String[] args){
//setHol();//UN COMMENT FOR QUESTION 2
//setHol2();//UN COMMENT FOR QUESTION 2
setPremierAndHol();
}
//<--------------------------------------------------------------------------------------------------------------------------------
public static void setHol() {
Holiday hol = new Holiday(null, null, null, null);
Holiday.setStartDate("1/1/1990");
Holiday.setEndDate("2/2/1992");
Holiday.setPlace("England");
Holiday.setPrice("£500");
}
//<--------------------------------------------------------------------------------------------------------------------------------
public static void setHol2() {
Holiday hol2 = new Holiday(null, null, null, null);
Holiday.setStartDate("5/5/1995");
Holiday.setEndDate("6/6/1996");
Holiday.setPlace("Scotland");
Holiday.setPrice("£200");
}
//<--------------------------------------------------------------------------------------------------------------------------------
public static void setPremierAndHol(){
Premier prem1 = new Premier(null, null, null, null, null, null, null);
Holiday.setStartDate("10/10/2000");
Holiday.setEndDate("11/11/2100");
Holiday.setPlace("Germany");
Holiday.setPrice("£900");
Premier.setHotelGrade("****");
Premier.setHotelName("Java Hotel");
Premier.setResortName("C++ Garden");
}
//<--------------------------------------------------------------------------------------------------------------------------------
}
Many thanks for your help in this matter.
P.S I also have one other minor issue with another project, should I make a new topic or is two topics in two minutes against etiquete?