Question: Refer to the class Student given below for Question 3: public class Student { private int id; private double marks; public Student (int id, double

 Refer to the class Student given below for Question 3: publicclass Student { private int id; private double marks; public Student (intid, double marks) { this.id=id; this.marks=marks; } public int getID () {return this.id; } public double getMarks () { return this.marks; } publicString toString() { return ("ID="+this.id+", marks="+this.marks); } (a) The class below can

Refer to the class Student given below for Question 3: public class Student { private int id; private double marks; public Student (int id, double marks) { this.id=id; this.marks=marks; } public int getID () { return this.id; } public double getMarks () { return this.marks; } public String toString() { return ("ID="+this.id+", marks="+this.marks); } (a) The class below can be used to represent a node in a Singly-Linked List. public class Student Node { private Student data; private StudentNode next; public StudentNode (Student data) { this.data=data; } public Student getData() { return data; } public void setNext (StudentNode nextStudent) { this.next=nextStudent; } public StudentNode getNext() { return next; } A class StudentLinked List can be built using objects of type StudentNode as follows: public class Student LinkedList { //The root of a linked list private StudentNode root; //methods } (i) Write a method addLast for the class StudentLinked List that takes as argument a Student object and inserts it at the end of the corresponding linked list [4 marks] Write a method delete Student for the class StudentLinkedList that takes as argument a student ID and deletes the corresponding node from the linked list, if a student object with that id exists. [5 marks] (ii) (c) The class StudentQueue implements a queue of Student objects using the class Student, and an array as the physical implementation as follows: public class Student Queue { private Student[] queueElements; private int front, rear, maxElements; public StudentQueue (int m) { // Constructor } public boolean isEmpty() { // Check if queue is empty } public boolean isFull() { // check if queue is full } public void enQueue (Student s) { // add a new element in the queue } public Student deQueue () { // remove an element from the queue } public int getSize() { // return maximum size of queue } } Write a function PrintQueue that takes as argument a Queue object and displays the contents of the queue without destroying it. [5 marks] A stack of Student objects is to be built using the class Student, and an array as the physical implementation, as follows: public class Student Stack { private Student[] stackElements; private int Top, maxElements; public Student Stack(int m) { Top=-1; ma xElements=m; stackElements=new Student[maxElements); } public boolean is Empty () { return (Top==-1); } public boolean is Full() { return (Top== (maxElements-1)); } public void push (Student s) { // To complete } public Student pop() { // To complete } } Complete the methods (i) push that would add an object of type Student onto the stack, if the stack is not full. [3 marks] pop that would return the topmost object from the stack if the stack is not empty. [3 marks] (ii) (Continued next page) Refer to the class Student given below for Question 3: public class Student { private int id; private double marks; public Student (int id, double marks) { this.id=id; this.marks=marks; } public int getID () { return this.id; } public double getMarks () { return this.marks; } public String toString() { return ("ID="+this.id+", marks="+this.marks); } (a) The class below can be used to represent a node in a Singly-Linked List. public class Student Node { private Student data; private StudentNode next; public StudentNode (Student data) { this.data=data; } public Student getData() { return data; } public void setNext (StudentNode nextStudent) { this.next=nextStudent; } public StudentNode getNext() { return next; } A class StudentLinked List can be built using objects of type StudentNode as follows: public class Student LinkedList { //The root of a linked list private StudentNode root; //methods } (i) Write a method addLast for the class StudentLinked List that takes as argument a Student object and inserts it at the end of the corresponding linked list [4 marks] Write a method delete Student for the class StudentLinkedList that takes as argument a student ID and deletes the corresponding node from the linked list, if a student object with that id exists. [5 marks] (ii) (c) The class StudentQueue implements a queue of Student objects using the class Student, and an array as the physical implementation as follows: public class Student Queue { private Student[] queueElements; private int front, rear, maxElements; public StudentQueue (int m) { // Constructor } public boolean isEmpty() { // Check if queue is empty } public boolean isFull() { // check if queue is full } public void enQueue (Student s) { // add a new element in the queue } public Student deQueue () { // remove an element from the queue } public int getSize() { // return maximum size of queue } } Write a function PrintQueue that takes as argument a Queue object and displays the contents of the queue without destroying it. [5 marks] A stack of Student objects is to be built using the class Student, and an array as the physical implementation, as follows: public class Student Stack { private Student[] stackElements; private int Top, maxElements; public Student Stack(int m) { Top=-1; ma xElements=m; stackElements=new Student[maxElements); } public boolean is Empty () { return (Top==-1); } public boolean is Full() { return (Top== (maxElements-1)); } public void push (Student s) { // To complete } public Student pop() { // To complete } } Complete the methods (i) push that would add an object of type Student onto the stack, if the stack is not full. [3 marks] pop that would return the topmost object from the stack if the stack is not empty. [3 marks] (ii) (Continued next page)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!