Implement solution for put( Student s)    (see code and description below)   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) {     public SLinkedList[] newStudentTable;         for (int i = 0; i < m; i++) {             newStudentTable[i] = new SLinkedList;         }           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;     }       public boolean put(Student s) {         // insert your solution here and modify the return statement         return false;     }     put( Student s) – returns true if the method successfully registers the student or adds the student onto the waitlist; returns false otherwise, namely in one of the three following cases: (1) if the student was already registered in the course, or (2) the student was already on the waitlist, or (3) the student had already reached their personal maximum of three courses. Assuming none of these three conditions was met, the student can then be either registered for the course or put on the waitlist. If the course is not yet at capacity, then the student can be registered. In that case, the student’s id is first used to determine where the student goes in the student table, namely in which linked list it goes: then, the student is put in the linked list in array slot id % m, where m is the length of the array (the course capacity). Note that you should go directly to slot id % m rather than iterating through all the slots. Indeed this is the entire point of taking the mod! If the course had already reached its registration capacity, then the student is added to the waitlist. If the waitlist was already at its full capacity, then the put() method increases the registration capacity of the course by 50%, as mentioned earlier – see waitlist field. (Increasing the capacity of the course by expanding the table is analogous to finding a bigger room). Use the changeArrayLength() method as a helper here. The put() method then registers all students currently on the waitlist, by moving them from the waitlist to the studentTable. (Note that the waitlist capacity is 50% of the course capacity, which was conveniently chosen such that all students in the waitlist can be registered.) Finally, the new student is added to the empty waitlist. For example, if the studentTable array length is 10 and the course is full (10 students registered) and the waitlist was already full (5 students on waitlist), the method would increase the table size – that is, capacity – to 15 and make a new empty waitlist. The new student would then be added to this empty waitlist. Note that the maximum size of the new waitlist would be 7, since the course capacity has increased.

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 solution for put( Student s)    (see code and description below)

 

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) {

    public 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;

    }

 

    public boolean put(Student s) {

        // insert your solution here and modify the return statement

        return false;

    }

 

 

put( Student s) – returns true if the method successfully registers the student or adds the student onto the waitlist; returns false otherwise, namely in one of the three following cases: (1) if the student was already registered in the course, or (2) the student was already on the waitlist, or (3) the student had already reached their personal maximum of three courses. Assuming none of these three conditions was met, the student can then be either registered for the course or put on the waitlist. If the course is not yet at capacity, then the student can be registered. In that case, the student’s id is first used to determine where the student goes in the student table, namely in which linked list it goes: then, the student is put in the linked list in array slot id % m, where m is the length of the array (the course capacity).

Note that you should go directly to slot id % m rather than iterating through all the slots. Indeed this is the entire point of taking the mod!

If the course had already reached its registration capacity, then the student is added to the waitlist. If the waitlist was already at its full capacity, then the put() method increases the registration capacity of the course by 50%, as mentioned earlier – see waitlist field. (Increasing the capacity of the course by expanding the table is analogous to finding a bigger room). Use the changeArrayLength() method as a helper here. The put() method then registers all students currently on the waitlist, by moving them from the waitlist to the studentTable. (Note that the waitlist capacity is 50% of the course capacity, which was conveniently chosen such that all students in the waitlist can be registered.) Finally, the new student is added to the empty waitlist. For example, if the studentTable array length is 10 and the course is full (10 students registered) and the waitlist was already full (5 students on waitlist), the method would increase the table size – that is, capacity – to 15 and make a new empty waitlist. The new student would then be added to this empty waitlist. Note that the maximum size of the new waitlist would be 7, since the course capacity has increased.

Expert Solution
trending now

Trending now

This is a popular 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