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) {
Step by step
Solved in 2 steps with 1 images