-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
87 lines (68 loc) · 2.22 KB
/
Student.java
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
public class Student {
//data
private String name;
private int gradeLevel;
private String mathScore;
private String englishScore;
private String csScore;
//constructor
public Student(String name, int gradeLevel, String mathScore, String englishScore, String csScore) {
setName(name);
setGradeLevel(gradeLevel);
this.mathScore = mathScore;
this.englishScore = englishScore;
this.csScore = csScore;
}
//functions - abilities
//getters and setters baybee
public String getName(){
return this.name;
}
public int getGradeLevel(){
return this.gradeLevel;
}
public void setName(String name){
this.name = name;
}
public void setGradeLevel(int gradeLevel){
if (gradeLevel >= 9 && gradeLevel <= 12){
this.gradeLevel = gradeLevel;
}
}
public void setMathScore(String mathScore){
if (mathScore.equals("A") || mathScore.equals("B") || mathScore.equals("C") || mathScore.equals("D") || mathScore.equals("F")){
this.mathScore = mathScore;
}
}
public void setEnglishScore(String englishScore){
if (englishScore.equals("A") || englishScore.equals("B") || englishScore.equals("C") || englishScore.equals("D") || englishScore.equals("F")){
this.englishScore = englishScore;
}
}
public void setCsScore(String csScore){
if (csScore.equals("A") || csScore.equals("B") || csScore.equals("C") || csScore.equals("D") || csScore.equals("F")){
this.csScore = csScore;
}
}
//calculate gpa
private double convertGrade(String grade){
if (grade.equals("A")){
return 4.0;
}
else if (grade.equals("B")){
return 3.0;
}
else if (grade.equals("C")){
return 2.0;
}
else if (grade.equals("D")){
return 1.0;
}
else{
return 0.0;
}
}
public double calculateGPA(){
return (convertGrade(mathScore) + convertGrade(englishScore) + convertGrade(csScore))/3;
}
}