This repository was archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathCourse.java
More file actions
97 lines (66 loc) · 1.59 KB
/
Course.java
File metadata and controls
97 lines (66 loc) · 1.59 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
public class Course {
private String name;
private int Credits;
private int remainingSeats;
private Student[] roster;
public Course( String name, int Credits, int numberofSeats) {
this.name = name;
this.Credits = Credits;
this.remainingSeats = numberofSeats;
this.roster = new Student[numberofSeats];
}
public String getName() {
return name;
}
public int getCredits() {
return Credits;
}
public int getRemainingSeats() {
return remainingSeats;
}
public Student[] getRoster() {
return roster;
}
public boolean addStudent(Student student) {
if (this.remainingSeats == 0) {
return false;
}
for(int i = 0; i < this.roster.length; i++) {
if(this.roster[i] != null && this.roster[i].getName() == student.getName() ) {
return false;
}
}
this.roster[this.roster.length - this.remainingSeats ] = student;
this.remainingSeats -= 1;
return true;
}
public String generateRoster() {
String rosterNames = "";
for(int i = 0; i < this.roster.length; i++) {
if(this.roster != null) {
String names = roster[i].getName();
rosterNames += names + "\n";
}
}
return rosterNames;
}
public double averageGPA(){
double sumGPA = 0.0;
int numberGPA = 0;
for( int i = 0; i < this.roster.length; i++)
{
if(this.roster[i] != null) {
sumGPA += this.roster[i].getGPA();
numberGPA ++;
}
}
double averageGPA = sumGPA/numberGPA;
return averageGPA;
}
public String toString() {
return this.name + " (" + this.Credits + ")";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}