I need to write changeArrayLength(int m) – void method; I already have the code (attached below) but it needs debugging... This method creates a new student table for this course; this new table has the given length m; the method moves all registered students to this table. This method creates a new array of SLinkedList, moves all the registered students into these linked lists, and changes this course’s studentTable field so it references this new table instead. Each student in the current table will be moved to the new table. This will require in most cases that the student is moved to a different array slot index. The slot index for the SLinkedList that they are moved to is id % m, where m is the new length of the array (the parameter of the method). The motivation for increasing the capacity of the array is that it keeps the average lengths of the linkedlists below 1, which tends to mean a fast traversal of each linked list. public class Course { public String code; public int capacity; public SLinkedList[] studentTable; public int size; public SLinkedList waitlist; public Course(String code) { this.code = code; this.studentTable = new SLinkedList[10]; this.size = 0; this.waitlist = new SLinkedList(); 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 void changeArrayLength(int m) {
I need to write changeArrayLength(int m) – void method; I already have the code (attached below) but it needs debugging...
This method creates a new student table for this course; this new table has the given length m; the method moves all registered students to this table.
This method creates a new array of SLinkedList<Student>, moves all the registered students into these linked lists, and changes this course’s studentTable field so it references this new table instead. Each student in the current table will be moved to the new table. This will require in most cases that the student is moved to a different array slot index. The slot index for the SLinkedList<Student> that they are moved to is id % m, where m is the new length of the array (the parameter of the method).
The motivation for increasing the capacity of the array is that it keeps the average lengths of the linkedlists below 1, which tends to mean a fast traversal of each linked list.
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 void changeArrayLength(int m) {
![1 public class Course {
public String code;
public int capacity;
public SLinkedList<Student> [] studentTable;
public int size;
public SLinkedList<Student> waitlist;
4
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;
}
10
11
12
13
14
15
16
17e
18
public Course(String code, int capacity) {
this.code = code;
this.studentTable = new SLinkedList[capacity];
this.size = 0;
this.waitlist = new SLinkedList<>();
this.capacity = capacity;
19
20
21
22
23
24
public void changeArrayLength(int m) I
public SLinkedList<Student> [] newStudentTable;
for (int i = 0; i < m; i++) {
newStudentTable[i] = new SLinkedList<Student2;
}
25e
26
27
28
29
30
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
33
34
35
36
37
38
studentTable = newStudentTable;
}
39
40](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9c002e4e-ece1-4dd1-9934-cbb442392244%2F051a058e-0674-44f6-9f7e-f9e97217b35a%2Fn200sb_processed.png&w=3840&q=75)


Step by step
Solved in 2 steps with 1 images









