Implement solutions for the following methods: • getCourseSize() – returns the number of students registered in the course (not in the waitlist). It should maintain the public size variable that keeps track of the number of students registered.  • getRegisteredIDs() – returns an array of int[], namely registered student id’s. The length of the array is the size (number of students) in the course. • getRegisteredStudents() – returns an array of type Student[], namely the registered Students. The length of the array is the current size (number of students) of the course. • getWaitlistedIDs() – returns an array of type int[], namely the ids of students in the waitlist. • getWaitlistedStudents() – returns an array of Students in the waitlist.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Implement solutions for the following methods:

• getCourseSize() – returns the number of students registered in the course (not in the waitlist). It should maintain the public size variable that keeps track of the number of students registered. 

getRegisteredIDs() – returns an array of int[], namely registered student id’s. The length of the array is the size (number of students) in the course.

• getRegisteredStudents() – returns an array of type Student[], namely the registered Students. The length of the array is the current size (number of students) of the course.

• getWaitlistedIDs() – returns an array of type int[], namely the ids of students in the waitlist.

• getWaitlistedStudents() – returns an array of Students in the waitlist.

 

 

public class Course {

    public String code;

    public int capacity;

    public SLinkedList<Student>[] studentTable;

    public int size;

    public SLinkedList<Student> waitlist;

 

 

    public Course(String code) {

        this.code = code;

        this.studentTable = new SLinkedList[10];

        this.size = 0;

        this.waitlist = new SLinkedList<Student>();

        this.capacity = 10;

    }

 

    public Course(String code, int capacity) {

        this.code = code;

        this.studentTable = new SLinkedList[capacity];

        this.size = 0;

        this.waitlist = new SLinkedList<>();

        this.capacity = capacity;

    }

 

    public int getCourseSize() {

        // insert solution here and modify the return statement

        return -1;

    }

 

 

    public int[] getRegisteredIDs() {

        // insert solution here and modify the return statement

        return null;

    }

 

    public Student[] getRegisteredStudents() {

        // insert solution here and modify the return statement

        return null;

    }

 

    public int[] getWaitlistedIDs() {

        // insert solution here and modify the return statement

        return null;

    }

 

    public Student[] getWaitlistedStudents() {

        // insert solution here and modify the return statement

        return null;

    }

public String tostring() {
30
4
String s = "Course: "+ this.code +"\n";
S +=
-\n";
for (int i = 0; i < this.studentTable.length; i++) {
|\n";
s += "|"+i+"
s += "|
SLinkedList<Student> list = this.studentTable[i];
if (list != null) {
for (int j = 0; j < list.size(); j++) {
------> ":
Student student = list.get(j);
S +=
student.id + ": "+ student.name +" --> ";
4
}
}
S += "\n-
--\n\n";
}
return s;
}
}
1
Transcribed Image Text:public String tostring() { 30 4 String s = "Course: "+ this.code +"\n"; S += -\n"; for (int i = 0; i < this.studentTable.length; i++) { |\n"; s += "|"+i+" s += "| SLinkedList<Student> list = this.studentTable[i]; if (list != null) { for (int j = 0; j < list.size(); j++) { ------> ": Student student = list.get(j); S += student.id + ": "+ student.name +" --> "; 4 } } S += "\n- --\n\n"; } return s; } } 1
1 public class Course {
public String code;
public int capacity;
public SLinkedList<Student> [] studentTable;
public int size;
public SLinkedList<Student> waitlist;
4
5
6.
7
8
public Course(String code) {
this.code = code;
this.studentTable = new SLinkedList[10];
this.size = 0;
this.waitlist = new SLinkedList<Student>();
this.capacity
}
10
11
12
13
14
= 10;
15
16
public Course(String code, int capacity) {
this.code = code;
this.studentTable = new SLinkedList[capacity];
this.size = 0;
this.waitlist = new SLinkedList<>();
this.capacity = capacity;
}
17e
18
19
20
21
22
23
24
O 250
虽26
® 27
O 28
29
public void changeArrayLength(int m) {
public SLinkedList<Student>[] newStudentTable;
for (int i = 0; i < m; i++) {
newStudentTable[i] = new SLinkedList<Student>;
}
30
O 31
for (int i = 0; i < studentTable. length; i++) {
for (int j = 0; j < studentTable[i].size(); j++) {
int tempIndex = studentTable[i].get(j). getId() % m;
newStudentTable[tempIndex].add (studentTable[i].get(j));
}
}
32
A 33
x 34
35
36
37
38
studentTable = newStudentTable;
Transcribed Image Text:1 public class Course { public String code; public int capacity; public SLinkedList<Student> [] studentTable; public int size; public SLinkedList<Student> waitlist; 4 5 6. 7 8 public Course(String code) { this.code = code; this.studentTable = new SLinkedList[10]; this.size = 0; this.waitlist = new SLinkedList<Student>(); this.capacity } 10 11 12 13 14 = 10; 15 16 public Course(String code, int capacity) { this.code = code; this.studentTable = new SLinkedList[capacity]; this.size = 0; this.waitlist = new SLinkedList<>(); this.capacity = capacity; } 17e 18 19 20 21 22 23 24 O 250 虽26 ® 27 O 28 29 public void changeArrayLength(int m) { public SLinkedList<Student>[] newStudentTable; for (int i = 0; i < m; i++) { newStudentTable[i] = new SLinkedList<Student>; } 30 O 31 for (int i = 0; i < studentTable. length; i++) { for (int j = 0; j < studentTable[i].size(); j++) { int tempIndex = studentTable[i].get(j). getId() % m; newStudentTable[tempIndex].add (studentTable[i].get(j)); } } 32 A 33 x 34 35 36 37 38 studentTable = newStudentTable;
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY