i am studying java at home and using online forums and resources (course fees too expensive)
i recently came across some assignment and i have been trying to do it to no avail.
can someone please help me with a few stages.
basically ive completed first two stages (classes) and the third stage involves inheritance and designing a third "student" and "part time" that inherits from "class person"
class date
public class Date
{
private int day, month,year;
public Date(int dd, int mm, int yy)
{
day=dd;
month=mm;
year=yy;
}
public Date(Date other)
{
this(other.day,other.month,other.year);
}
public boolean equals (Date other)
{
return day==other.day && month==other.month &&
year==other.year;
}
public void copy(Date other)
{
day=other.day;
month=other.month;
year=other.year;
}
public String monthAsString()
{
switch (month)
{
case 1: return "JANUARY";
case 2: return "FEBUARY";
case 3: return "MARCH";
case 4: return "APRIL";
case 5: return "MAY";
case 6: return "JUNE";
case 7: return "JULY";
case 8: return "AUGUST";
case 9: return "SEPTEMBER";
case 10: return "OCTOBER";
case 11: return "NOVEMBER";
case 12: return "DECEMBER";
default: return "error";
}
}
public boolean lessThan(Date other)
{
if (year < other.year)
return true;
else if (year > other.year)
return false;
else if (month < other.month)
return true;
else if (month > other.day)
return false;
else if (day< other.day)
return true;
else if (day >= other.day)
return false;
else return true;
}
public String toString ()
{
return "day" +day+ "month" + month + "year" + year;
}
}
and class person
public class Person
{
protected String name;
protected String gender;
protected Date dateOfBirth;
protected String address;
protected String natInsceNo;
protected String phoneNo;
protected static int counter;
public Person()
{
name="";
gender="";
natInsceNo="";
phoneNo="";
counter++;
}
public Person (String nme, char sex, Date dob)
{
dateOfBirth = new Date(dob);
setGender(sex);
name = nme;
address ="";
counter++;
} //end constructor
public Person(Person other)
{
name = other.name;
dateOfBirth = other.dateOfBirth;
gender = other.gender;
address = other.address;
natInsceNo = other.natInsceNo;
}
public String getname()
{
return name;
}
public void setGender (char gen)
{
if (gen == 'm' || gen == 'M')
gender = "male";
else if (gen == 'f' || gen == 'F')
gender = "female";
else System.out.println("unknown");
}
public static int count()
{
return counter;
}
public String getAddress()
{
return address;
}
public Date dob()
{
return dob();
}
public String natInsceNo()
{
return natInsceNo;
}
public String phoneNo()
{
return phoneNo;
}
public void copy(Person other)
{
name = other.name;
dateOfBirth = other.dateOfBirth;
address = other.address;
natInsceNo = other.natInsceNo;
gender = other.gender;
}
public boolean equals(Person other)
{
return dateOfBirth.equals(other.dateOfBirth) && natInsceNo.equals(other.natInsceNo) &&
dateOfBirth.equals(other.dateOfBirth);
}
public void setAddress(String newAddress)
{
address = newAddress;
}
}
i now need a third class "student" that inherits from class person and a "class part time" that also inherits from "class person"
showing
protected variables
dateEnrolled //Date
course // String
year // int
constructor
Student()
// post variables set to non-null values;
Student (String nme, char sex, Date dob,
String insceNumber, Date enrolled)
// pre dob != null enrolled != null
// post variables initialised with params passed in
Note that both these constructors should also call the
inherited constructor.
The clone constructor should also call the inherited constructor;
transformers
void setCourse(String s)
// pre s is not null
// post course is set to s
void setYear(int yr)
// 0 < yr
// post year is set to yr
Note that the copy should also call the inherited copy
accessors
No additional ones specified.
The toString() method should also call the inherited toString.
There is no need for a new equals method for this class.
AND
Design and code class PartTime, which inherits from Student.
protected variables
employer // String
workAddress // String
workPhoneNo // String
constructor
PartTime()
// post variables set to non-null values;
PartTime (String nme, char sex, Date dob,
String insceNumber, Date enrolled)
// pre dob != null enrolled != null
// post variables initialised with params passed in
Note that both these constructors should also call the
inherited constructor.
The clone constructor should also call the inherited constructor;
transformers
void setEmployer(String emp)
// pre emp is not null
// post employer is set to emp
void setWorkAddress(String wAddr)
// pre wAddr is not null
// post workAddress is set to wAddr
void setWorkPhone(String wPhone)
// pre wPhone is not null
// post workPhone is set to wPhone
Note that the copy should also call the inherited copy
accessors
No additional ones specified.
The toString() method should also call the inherited toString().
There is no need for a new equals method for this class.
SOMEONE HELP ME IM STUCK! im supposed to follow this with a "class store" etc but im fine with those just these last two steps are worrying!