This is the question:
Write code that defines a class of objects called Exam, such that each exam object from that
class contains the exam name (a String), the exam location (a String), the exam day (an int
representing the date in the month the exam takes place on), the exam month (an int representing the
exam month) and the exam year (another int). Define a constructor for this class that takes name,
location, day, month, and year as input and initialises an exam object. Define a toString method for
the class that returns a string like: “COMP10020 Introduction to Programming II: RDS
Simmonscourt, 9/5/2006.” Define a compareTwo(Exam ex) method that returns true if this exam
object occurs before the argument exam ex (comparing the day, month, and years of the two exams),
and false if the two exams occur on the same date or the ex exam occurs before this one.
here is my answer:
class Exam{
public String examName;
public String examLocation;
public int examDate;
public int examMonth;
public int examYear;
public Exam(String n, String l, int d, int m, int y){
examName = n;
examLocation = l;
examDate = d;
examMonth = m;
examYear = y;
}
public String toString(){
return examName +": " +examLocation+", " +examDate+"/"+examMonth+"/"+examYear+". ";
}
}
public class compareTwo{
public static boolean compareTwo(Exam ex) {
if (examYear < 2006){
return false;
}
else if (examYear > 2006){
return true;
}
else if (examMonth < 5){
return false;
}
else if (examMonth > 5){
return tru;
}
else if (examDay =< 9){
return false;
}
else if (examDay > 9){
return true;
}
System.exit(0);
}
}