import java.io.*; public class MyStudent extends MyPerson implements Comparable{
ID: 3584292 • Letter: I
Question
import java.io.*; public class MyStudent extends MyPerson implements Comparable{ String studNum; String course; public MyStudent(String fn, String ln, MyDate bd, Sex s, String sn, String crs){ this.firstName = fn; this.lastName = ln; this.BirthDate = bd; this.sex = s; this.studNum = sn; this.course = crs; } public void writeUp(){ System.out.println(this.firstName+ " "+this.lastName+", "+this.sex+" with student number "+this.studNum+", was born on "+this.BirthDate+" and is taking "+this.course+"."); } public String toString() { return this.studNum+": "+this.lastName+", "+this.firstName; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (this.getClass() != obj.getClass()) return false; return (this.studNum.equals(((MyStudent)obj).studNum)); // == will not work! } public int hashCode() { return this.studNum.hashCode(); // was specified as hashCode of lastName in exam spec } public int compareTo(MyStudent that) { return this.studNum.compareTo(that.studNum); } public static void main(String[] args) { MyStudent[] M = new MyStudent[3]; BufferedReader fileIn = new BufferedReader(new FileReader("MyStudent.input")); for (int i=0; i<3; i++) { String[] token = fileIn.readLine().split("::"); Sex sx = Sex.male; if (token[2].equals("F")) sx = Sex.female; MyDate md = new MyDate(token[5],token[6],token[7]); M[i] = new MyStudent(token[1],token[0], md, sx, token[3], token[4]); System.out.println(" "+M[i]+" "+M[i].hashCode()); M[i].writeUp(); } } }Explanation / Answer
fixed :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.