-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
125 lines (104 loc) · 2.65 KB
/
Student.java
File metadata and controls
125 lines (104 loc) · 2.65 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
/**
* A class Student.
* @author Lisa Miller
* @since 9/5/24
*/
public class Student {
/** The Student's name. */
private String name = "";
/** The Student's ID number. */
private int id = 0;
/** The Student's grade point average. */
private double gpa = -1;
/**
* Two parameter Student constructor, GPA is default value -1.
* @param newName the student's name
* @param newID the student's ID number
*/
public Student(String newName, int newID) {
this.name = newName;
this.id = newID;
} //constructor ends.
/**
* Three parameter Student constructor.
* @param newName the student's name
* @param newID the student's ID number
* @param newGPA the student's GPA
*/
public Student(String newName, int newID, double newGPA) {
this.name = newName;
this.id = newID;
this.gpa = newGPA;
} //constructor ends.
/**
* Formats Student object for printing.
* If GPA is default value, prints.
* GPA not yet calculated.
* @return a String representation of Student
*/
public String toString() {
String s = "";
s = "Name: " + this.name;
s = s + "\nStudent ID: " + this.id;
if (this.gpa < 0) {
s = s + "\nGPA not yet calculated";
}
else {
s = s + "\nGPA: " + this.gpa;
}
return s;
}
/** Gets methods. */
/**
* Retrieves the Student ID.
* @return the Student's ID number
*/
public int getID() {
return this.id;
}
//
/**
* retrieves the Student GPA.
* @return the Student's GPA
*/
public double getGPA() {
return this.gpa;
}
/**
* Retrieves the Student name.
* @return the Student's name
*/
public String getName() {
return this.name;
}
/* Sets methods. */
/**
* Changes the Student ID.
* @param newID the Student's new ID number
*/
public void setID(int newID) {
this.id = newID;
}
/**
* Changes the Student GPA.
* @param newGPA the Student's new GPA
*/
public void setGPA(double newGPA) {
this.gpa = newGPA;
}
/**
* Changes the Student name.
* @param newName the Student's new name
*/
public void setName(String newName) {
this.name = newName;
}
/**
* driver to test Students.
* @param args not used.
*/
public static void main(String[] args) {
Student s = new Student("Frank", 3423, 3.0);
System.out.println(s);
} //end driver
} // end of class Student