-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
149 lines (136 loc) · 4.07 KB
/
Student.java
File metadata and controls
149 lines (136 loc) · 4.07 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
147
148
149
/**
* Thic class creates objects of the Student type
*
* @author Michael Chadwick
* @version 5/13/2020 Final Student Search
*/
import java.lang.Exception;
import java.lang.String;
public class Student implements Comparable<Student>
{
private int studId;
private String studName;
private String studMajor;
/**
* Constructs a Student object with default values
*/
public Student()
{
studId = 0;
studName = " ";
studMajor = " ";
}
/**
* Constructor for objects of class Student
* @param studId - the student ID to be used in the search
*/
public Student(int studId)
{
this.studId = studId;
this.studName = " ";
this.studMajor = " ";
}
/**
* Constructor for Student object with parameter values
* @param studId - the student's ID
* @param studName - the student's name
* @param studMajor - the student's major
* @throw Exception - passed on from Student set methods
*/
public Student(int studId, String studName, String studMajor) throws Exception
{
setId(studId);
setName(studName);
setMajor(studMajor);
}
/**
* Gets the cards type
* @return studId - returns the student's ID number
*/
public int getId()
{
return this.studId;
}
/**
* Sets the student's ID number
* @pram studId - sets the student's ID number
* @throw Exception - chekcs that the Student object if it alreadys has a number
* and that it's greater than zero
*/
public void setId(int studId) throws Exception
{
if(studId > 0)
if(this.studId == 0)
this.studId = studId;
else
throw new Exception("The student ID already exists.\n");
else
throw new Exception("Student's ID must be greater than zero.\n");
}
/**
* Gets the student's name
* @return studName - returns the student's name
*/
public String getName()
{
return this.studName;
}
/**
* Sets the student's Name
* @param studName - sets the student's name
* @throw Exception = if the name is blank
*/
public void setName(String studName) throws Exception
{
if(studName == null)
throw new Exception("A name must be provided.\n");
studName = studName.trim();
if(studName.length() > 0)
this.studName = studName;
else
throw new Exception("A name must be provided.\n");
}
/**
* Gets the student's major
* @return getMajor - returns the student's major
*/
public String getMajor()
{
return this.studMajor;
}
/**
* Sets the student's major
* @param studMajor - sets the student's major
* @throw Exception - if it does'nt meet the minimum length
*/
public void setMajor(String studMajor) throws Exception
{
studMajor = studMajor.trim();
if(studMajor.length() == 3)
this.studMajor = studMajor.toUpperCase();
else
throw new Exception("The major must be three characters long.\n");
}
/**
* Overrides the standard compareTo method offered by Object to get the proper output
* for our subclass Student object
* Compares two Student objects for proper sequencing in our BinarySearchTree
* @param otherObject - which is a Student object to compare with the host Student object
* @return - a integer representing the difference between the two objects
*/
@Override
public int compareTo(Student otherStudent)
{
return studId - otherStudent.studId;
}
/**
* Overrides the standard toString method offered by Object to get the proper output
* for our subclass Student object
* @return String - returns all the variable's associated to a student formatted to readability
*/
@Override
public String toString()
{
return String.format("%8d %-20s %s\n", studId, studName, studMajor);
}
}