-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCourse.java
More file actions
67 lines (54 loc) · 1.47 KB
/
Course.java
File metadata and controls
67 lines (54 loc) · 1.47 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
package chapter_ten;
public class Course
{
private String courseName;
private String[] students = new String[100];
private int numberOfStudents;
public Course(String courseName)
{
this.courseName = courseName;
}
public void addStudent(String student)
{
if (numberOfStudents >= students.length)
{
String[] newArray = new String[numberOfStudents*2];
System.arraycopy(students, 0, newArray,
0, numberOfStudents+1);
students = newArray;
}
students[numberOfStudents++] = student;
}
public String[] getStudents()
{
String[] realStudents = new String[numberOfStudents];
System.arraycopy(students, 0, realStudents,
0, numberOfStudents);
return realStudents;
}
public int getNumberOfStudents()
{
return numberOfStudents;
}
public String getCourseName()
{
return courseName;
}
public void clear()
{
students = new String[students.length];
}
public void dropStudent(String studentName)
{
boolean reach = false;
for (int i = 0; i <= numberOfStudents-1;i++) {
if (!reach)
if (students[i].equals(studentName))
reach = true;
if (reach)
if (i < numberOfStudents - 1)
students[i] = students[i + 1];
}
numberOfStudents--;
}
}