Question: Java MyLinkedList list1 = new MyLinkedList(); I need help with the question 6 and 8 5. Add a new PartTime student at index 2 in
Java
MyLinkedList list1 = new MyLinkedList();
I need help with the question 6 and 8
5. Add a new PartTime student at index 2 in the list then remove the student at index 1 from the list. Display the list 6. Check if the newly added PartTime student is in the list using contains method, then display its index which should be 1. // contains, indexOf 7. Change the title of the name of the newly added student to John Doe. // set 8. Construct a MyLinkedList object from an array of mixed students then display the list.
public interface MyList { public void clear(); public boolean isEmpty(); public boolean contains(E object); public int indexOf(E object); public E get(int index); public E set(E e, int index); public int size(); public void add(int index, E object); public E remove(int index); }
public interface MyList {
public void clear();
public boolean isEmpty();
public boolean contains(E object);
public int indexOf(E object);
public E get(int index);
public E set(E e, int index);
public int size();
public void add(int index, E object);
public E remove(int index);
}
abstract class Student { protected int id; protected String name; protected double registrationFees; public Student(int id, String name) { this.id = id; this.name = name; } public int getId() { return id; } public String getName() { return name; } public double getRegistrationFees() { return registrationFees; } abstract public void setFees(); } class PartTime extends Student { public PartTime(int id, String name) { super(id, name); setFees(); } @Override public void setFees() { super.registrationFees = 700; } @Override public String toString() { return "PartTime{" + "id=" + id + ", name='" + name + '\'' + ", registrationFees=" + registrationFees + '}'; } } class FullTime extends Student { public FullTime(int id, String name) { super(id, name); setFees(); } @Override public void setFees() { super.registrationFees = 1200; } @Override public String toString() { return "FullTime{" + "id=" + id + ", name='" + name + '\'' + ", registrationFees=" + registrationFees + '}'; } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
