-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
129 lines (114 loc) · 3.24 KB
/
Student.java
File metadata and controls
129 lines (114 loc) · 3.24 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
/** A Student has a name, a BeltList (storing their belts), a beltIndex (used to access the BeltList), an age, and an entranceDate
*/
public class Student
{
private String name;
private BeltList beltList = new BeltList();
private int beltIndex;
private int age;
/** Constructs a Student object with a given name, a beltIndex and age of 0, and an entranceDate of "N/A"
* @param studentName the color of the Student
*/
public Student(String studentName)
{
name = studentName;
beltIndex = 0;
age = 0;
}
/** Constructs a Student object with a given name, belt, age
* @param studentName the name of the Student
* @param studentBelt the belt of the Student
* @param studentAge the age of the Student
*/
public Student(String studentName, int studentBelt, int studentAge)
{
name = studentName;
beltIndex = studentBelt;
age = studentAge;
}
/** Formats the Student object when printed
* @return the formatted String of the Student
*/
public String toString()
{
return "Name: " + name + "\nBelt: " + beltList.get(beltIndex).getName() + "\nAge: " + age;
}
public String showAllInfo()
{
return "Name: " + name + "\nAge: " + age + "\n" + beltList.get(beltIndex) + "\n\nIs this student eligible to test? " + beltList.get(beltIndex).testEligibility();
}
/** Changes the belt of the Student
* @param index the new beltIndex
*/
public void setBelt(int index)
{
beltIndex = index;
}
public String getName()
{
return name;
}
public int getBelt()
{
return beltIndex;
}
public Belt getBeltList()
{
return beltList.get(beltIndex);
}
public int getAge()
{
return age;
}
/** Edits Student information and returns new information
* @param studentName the name of the Student
* @param studentAge the age of the Student
* @return the new information of the Student
*/
public String editStudent(String studentName, int studentAge)
{
name = studentName;
age = studentAge;
return "Student information has now been set to the following: " + "\nName: " + name + "\nAge: " + age;
}
/** Evaluates whether Students share names
* @param o the name of the Object
* @return whether the Object and Student share names
*/
public boolean equals(Object o)
{
Student other = (Student) o;
return this.name.equals(other.name);
}
/** Compares Objects based on their names
* @param o the name of the Object
* @return comparison between Object and Student names
*/
public int compareTo(Object o)
{
Student other = (Student) o;
return this.name.toUpperCase().compareTo(other.name.toUpperCase());
}
/** Compares Objects based on their belts
* @param o the name of the Object
* @return comparison between Object and Student belts
*/
public int compareToByBelt(Object o)
{
Student other = (Student) o;
return (int) (beltIndex - other.beltIndex);
}
/** Compares Objects based on their ages
* @param o the name of the Object
* @return comparison between Object and Student belts
*/
public int compareToByAge(Object o)
{
Student other = (Student) o;
return (int) (age - other.age);
}
public String saveToFile()
{
return name + "\n" + beltIndex + "\n" + age;
}
}