-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
70 lines (58 loc) · 1.92 KB
/
Student.java
File metadata and controls
70 lines (58 loc) · 1.92 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
/*
* File: Student.java
* Author: Kris Sherbondy
* Date: 15 Oct 2017
* Purpose: This program is able to store data for several students. The user is
* able to create, update, delete, and find students in a database. The database
* stores information and is able to display that data in a JOptionPane for the user
* to see.
*/
package project4;
import java.text.DecimalFormat;
public class Student {
//Declaring all variables needed for the program to work.
private String name;
private String major;
private double credits;
private double qualityPoints;
private int gradePoints;
private double gpa = 4.0;
private static final DecimalFormat DF = new DecimalFormat("#0.00");
//Method for creating an instance of a student
Student(String name, String major) {
this.name = name;
this.major = major;
credits = 0;
qualityPoints = 0;
}
//This method has teh user put in what grade the student earned. Using a switch
//statement helps clean up the code. The GPA is then worked out and stored.
void courseCompleted(String grade, int creditHours) {
switch (grade) {
case "A":
gradePoints = 4;
break;
case "B":
gradePoints = 3;
break;
case "C":
gradePoints = 2;
break;
case "D":
gradePoints = 1;
break;
case "F":
gradePoints = 0;
break;
}
gradePoints = gradePoints*creditHours;
qualityPoints += gradePoints;
credits += creditHours;
gpa = qualityPoints/credits;
}
//Overridden toString() method used to display student name, major, and GPA.
@Override
public String toString() {
return "\nName: \t" + name + "\nMajor: \t" + major + "\nGPA: \t" + DF.format(gpa);
}
}