-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
146 lines (124 loc) · 3.04 KB
/
Student.java
File metadata and controls
146 lines (124 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import java.util.ArrayList;
///////////////////////////////////////////////////////////////////////////////
// ALL STUDENTS COMPLETE THESE SECTIONS
// Title: Database
// Files: Student.java
// Semester: Summer 2016
//
// Author: Scarlet Guo zguo74@wisc.edu
// CS Login: zguo74
// Lecturer's Name: GERALD
////////////////////PAIR PROGRAMMERS COMPLETE THIS SECTION ////////////////////
//
//Pair Partner: Qingxu Kong
//Email: qkong5@wisc.edu
//CS Login: qkong5
//////////////////////////// 80 columns wide //////////////////////////////////
/**
* this class represent a student object, which includes a unique ID, a name,
* birth year and an array list of the courses the student takes.
* @author Scarlet
*
*/
public class Student implements Comparable<Student> {
/**
* data field
* ID: unique student ID
* name: student's name
* year: student birth year
* courses: an array list of the courses the student is taking
* THISYEAR: an constant representing this year
*/
private int ID;
private String name;
private int year;
private ArrayList<Course> courses;
public static final int THISYEAR = 2016;
/**
* construct a new student project using specified name, year, and unique ID
* @param name
* @param year
* @param ID
*/
public Student (String name, int year, int ID) {
this.ID = ID;
this.name = name;
this.year = year;
this.courses = new ArrayList<Course> ();
}
/**
* this method add a course to a student's course list
* @param c
* @throws CourseExistException
*/
public void addCourse(Course c) throws CourseExistException {
for (Course e: this.courses) {
if (c.equalsTo(e) ) {
throw new CourseExistException();
}
}
this.courses.add(c);
}
/**
* a getter of student's name
* @return
*/
public String getName() {
return name;
}
/**
* setter of student's name
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* getter of student's birth year
* @return
*/
public int getYear() {
return this.year;
}
/**
* getter of the courses list of the student's
* @return
*/
public ArrayList<Course> getCourse() {
return this.courses;
}
/**
* getter of the student ID
* @return
*/
public int getID() {
return this.ID;
}
/**
* return a string of the formatted student information
*/
public String toString() {
StringBuilder s = new StringBuilder();
s.append("Name: " + this.name + "\nID: " + this.ID + "\nAge: "
+ (THISYEAR - this.year) + "\nCourses: \n");
for (int i = 0; i < courses.size(); i++){
s.append(this.courses.get(i).toString());
}
return s.toString();
}
/**
* setter of the students' birth year
* @param parseInt
*/
public void setYear(int parseInt) {
this.year = parseInt;
}
/**
* this method implements the comparable students
*/
@Override
public int compareTo(Student s) {
int compareID = s.getID();
return this.ID-compareID;
}
}