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.

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

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 void changeArrayLength(int m) {
SLinkedList<Student>[] newStudentTable;
for (int i = 0; i < m; i++) {
newStudentTable[i] = new SLinkedList<Student>;
}
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));
}
}
studentTable = newStudentTable;
Transcribed Image Text:public void changeArrayLength(int m) { SLinkedList<Student>[] newStudentTable; for (int i = 0; i < m; i++) { newStudentTable[i] = new SLinkedList<Student>; } 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)); } } studentTable = newStudentTable;
1 public class Student I
2
public int id;
public String name;
public SLinkedList<String> courseCodes;
3
4
6.
public final int COURSE_CAP
= 3;
%3D
7
public Student(int id, String name) {
this.id = id;
this.name = name;
this.courseCodes = new SLinkedList<String>();
}
86
9
%3D
10
11
12
13
140
15
16
17
180
19
20
21
220
23
24
25
public boolean isRegistered0rWaitlisted (String course) {
return this.courseCodes.getIndex0f (course) > -1;
}
public void addCourse(String course) {
this.courseCodes.addLast(course);
}
public void dropCourse(String course) {
this.courseCodes. remove(course);
}
public String toString(){
return "#" + this.id + "
}
260
" + this. name;
27
28
29
30 H
Transcribed Image Text:1 public class Student I 2 public int id; public String name; public SLinkedList<String> courseCodes; 3 4 6. public final int COURSE_CAP = 3; %3D 7 public Student(int id, String name) { this.id = id; this.name = name; this.courseCodes = new SLinkedList<String>(); } 86 9 %3D 10 11 12 13 140 15 16 17 180 19 20 21 220 23 24 25 public boolean isRegistered0rWaitlisted (String course) { return this.courseCodes.getIndex0f (course) > -1; } public void addCourse(String course) { this.courseCodes.addLast(course); } public void dropCourse(String course) { this.courseCodes. remove(course); } public String toString(){ return "#" + this.id + " } 260 " + this. name; 27 28 29 30 H
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