-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
44 lines (37 loc) · 1.08 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
package PBOS5;
public class Student extends Person{
private int numCourses;
private String[] courses;
private int[] grades;
private static final int MAX_COURSES = 30;
public Student(String name, String address) {
super(name, address);
numCourses = 0;
courses = new String[MAX_COURSES];
grades = new int[MAX_COURSES];
}
@Override
public String toString() {
return "Mahasiswa: " + super.toString();
}
public void addCourseGrade(String course, int grade) {
courses[numCourses] = course;
grades[numCourses] = grade;
++numCourses;
}
public void printGrades() {
System.out.print(this);
for (int i = 0; i < numCourses; ++i) {
System.out.println();
System.out.print(courses[i] + " : " + grades[i]);
}
System.out.println();
}
public double getAverageGrade() {
int sum = 0;
for (int i = 0; i < numCourses; i++ ) {
sum += grades[i];
}
return (double)sum/numCourses;
}
}