forked from Nnamdikeshi/Java2545examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathITECCourse.java
More file actions
42 lines (32 loc) · 1.05 KB
/
Copy pathITECCourse.java
File metadata and controls
42 lines (32 loc) · 1.05 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
package week6_first_classes.OOPITECCourseManager;
import java.util.ArrayList;
/**
* Stores data about an ITEC course.
*
*/
public class ITECCourse {
//Data that an ITECCourse object needs to store
String name;
int code;
ArrayList<String> students;
int maxStudents;
void addStudent(String studentName) {
if (students == null) { //See if students has been set up yet – initialize it if not
students = new ArrayList<String>();
}
students.add(studentName);
}
void writeCourseInfo() {
System.out.println("Course Name: " + name);
System.out.println("Course Code: " + code);
System.out.println("Students enrolled:");
for (String student : students) {
System.out.println(student);
}
System.out.println("There are " + getNumberOfStudents() + " students enrolled");
System.out.println("The max number of students for this course is " + maxStudents);
}
int getNumberOfStudents() {
return this.students.size();
}
}