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
48 lines (37 loc) · 1.27 KB
/
Copy pathITECCourse.java
File metadata and controls
48 lines (37 loc) · 1.27 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
package week6_first_classes.OOPITECCourseManager_Constructor;
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;
//Constructor
ITECCourse(String courseName, int courseCode, int courseMaxStudents) {
this.name = courseName;
this.code = courseCode;
this.students = new ArrayList<String>(); //Set up the students list
this.maxStudents = courseMaxStudents;
}
void addStudent(String studentName) {
//No need to create ArrayList, the constructor has already done it
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();
}
}