Date.java: represents a date. Bruin.java : represents everyone in UCLA , including employee and students. Student.java: represents a UCLA students. Professor.java: represents a UCLA professors. this or super to simplify your program. If your program is unnecesary long, points
will be taken off. private int year: year of the Dateprivate int month: monthprivate int day, day. public Date(int year, int month, int day)
public int getDay()public int getMonth()public int getYear()public String toString(): return the date is yyyy/mm/dd format. Example, if the date is
1991 Mar 23, the output should be 1999/03/23.
public class DateTest {
public static void main(String[] args) {
Date date = new Date(2003, 1, 30);
System.out.println(date.getYear());
System.out.println(date.getMonth());
System.out.println(date.getDay());
System.out.println(date);
date = new Date(2003, 11, 9);
System.out.println(date.getYear());
System.out.println(date.getMonth());
System.out.println(date.getDay());
System.out.println(date);
}
}
|
2003 1 30 2003/01/30 2003 11 9 2003/11/09 |
protected String ID : 9-digit IDprotected String name: nameprotected char gender : gender, M or Fprotected Date birthday : Date of birthprotected Date firstDay : first day in school public Bruin(String ID, String name, char gender, Date birthday, Date firstDay): constructorString toString() : see the sample output for the format
public class BruinTest {
public static void main(String[] args) {
Date bday = new Date(1980,2,23);
Date firstDay = new Date(2003, 9, 30);
Bruin bruin = new Bruin("123123235", "Helen Smith", 'F', bday, firstDay);
System.out.println(bruin);
}
}
|
ID: 123123235 Name: Helen Smith Gender: F Date of birth: 1980/02/23 In UCLA since: 2003/09/30 |
Bruin.
In addition to all the members given in Bruin,
the class has information about all the UCLA classes that the student took
and all the grades
public Student(String ID, String name, char gender, Date birthday, Date firstDay): constructor. public void addClass(String classID, int units, String grade) :
add a UCLA class with given classID, units and grade to the student's class list.
e.g addClass("PIC10A", 5, "A-"). If the classID already exists in the student's class list,
replace the original unit and grade by the new unit and grade.int getTotalUnits(): get the total unitsdouble getGPA(): return the GPA of the students. Return 0 if there is no class.Here is a function that you can use
private double getPoints(String grade) {
if(grade.equals("A+")) {
return 4;
} else if (grade.equals("A")) {
return 4;
} else if (grade.equals("A-")) {
return 3.7;
} else if(grade.equals("B+")) {
return 3.3;
} else if(grade.equals("B")) {
return 3;
} else if(grade.equals("B-")) {
return 2.7;
} else if(grade.equals("C+")) {
return 2.3;
} else if(grade.equals("C")) {
return 2.0;
} else if(grade.equals("C-")) {
return 1.7;
} else if(grade.equals("D+")) {
return 1.3;
} else if(grade.equals("D")) {
return 1;
} else {
return 0;
}
}
String toString() : see the same output.
public class StudentTest {
public static void main(String[] args) {
Date bday = new Date(1980,2,23);
Date firstDay = new Date(2003, 9, 30);
Student s = new Student("123123235", "Helen Smith", 'F', bday, firstDay);
System.out.println("getTotalUnits(): " + s.getTotalUnits());
System.out.println("getGPA(): " + s.getGPA());
System.out.println();
System.out.println(s);
s.addClass("PIC10A", 5, "A-");
s.addClass("PIC10B", 5, "B+");
s.addClass("PIC20A", 5, "A");
s.addClass("Math31A", 4, "C");
System.out.println("getTotalUnits(): " + s.getTotalUnits());
System.out.println("getGPA(): " + s.getGPA());
System.out.println();
System.out.println(s);
}
}
|
getTotalUnits(): 0 getGPA(): 0.0 ID: 123123235 Name: Helen Smith Gender: F Date of birth: 1980/02/23 In UCLA since: 2003/09/30 Class taken: Total units: 0 GPA: 0.0 getTotalUnits(): 19 getGPA(): 3.32 ID: 123123235 Name: Helen Smith Gender: F Date of birth: 1980/02/23 In UCLA since: 2003/09/30 Class taken: PIC10A 5 A- PIC10B 5 B+ PIC20A 5 A Math31A 4 C Total units: 19 GPA: 3.32 |
public class StudentTest2 {
public static void main(String[] args) {
Date bday = new Date(1984,2,23);
Date firstDay = new Date(2004, 9, 30);
Student s = new Student("144244422", "Mary Ford", 'F', bday, firstDay);
s.addClass("PIC10A", 5, "C-");
s.addClass("PIC10B", 5, "B");
System.out.println(s);
s.addClass("PIC10A", 5, "A") ; // replace the grade of PIC10A
System.out.println(s);
}
}
|
ID: 144244422 Name: Mary Ford Gender: F Date of birth: 1984/02/23 In UCLA since: 2004/09/30 Class taken: PIC10A 5 C- PIC10B 5 B Total units: 10 GPA: 2.35 ID: 144244422 Name: Mary Ford Gender: F Date of birth: 1984/02/23 In UCLA since: 2004/09/30 Class taken: PIC10A 5 A PIC10B 5 B Total units: 10 GPA: 3.5 |
Bruin. It has the following variables:
public int position: whether the professor is assistant, associate or full time professor.
It can be one of the following variables: public static final int ASSISTANT, ASSOCIATE, FULL.Professor(String ID, String name, char gender, Date birthday, Date firstDay, int position): constructorpublic int getSalary(): return the salary of the professor. It is calculated by the following method:String toString(): see the sample output.
public class ProfTest {
public static void main(String[] args) {
Date bday = new Date(1955,2,23);
Date firstDay = new Date(1997, 10, 8);
Professor prof = new Professor("123123235", "Dava Johnson", 'M', bday, firstDay, Professor.ASSOCIATE);
System.out.println(prof);
firstDay = new Date(1997, 1,1);
prof = new Professor("123123235", "Dava Johnson", 'M', bday, firstDay, Professor.ASSOCIATE);
System.out.println(prof);
}
}
|
ID: 123123235 Name: Dava Johnson Gender: M Date of birth: 1955/02/23 In UCLA since: 1997/10/08 Position: Associate Professor Salary: 268019 ID: 123123235 Name: Dava Johnson Gender: M Date of birth: 1955/02/23 In UCLA since: 1997/01/01 Position: Associate Professor Salary: 281420 |
(int)(x*100 + 0.5)/100.0
"\t" (tab) in the Student's toString() method to seperate data/** Name: Charles Li * Student ID : 000 000 000 * PIC ID: ccli * E-mail: ccli@math.ucla.edu * Discussion: 1A * Assignment: hw1 * * I, Charles Li, pledge that this is my own independent work, which * conforms to the guidelines of academic honesty as described in the course * syllabus. * */