SlideShare a Scribd company logo
Implementation The starter code includes List.java. You should not change anything in List.java.
Your task will be to create LinkedList.java, make LinkedList use generics and inherit from List,
and complete several methods in LinkedList.java. Create LinkedList.java in IntelliJ. Add a main
method to LinkedList.java containing the following code. Your program will not compile again.
public static void main(String[] args) { LinkedList list = new LinkedList();
System.out.println(list.getHead()); System.out.println(list.getTail()); list.add("first");
list.add("middle"); list.add("last"); System.out.println(list.getHead().value);
System.out.println(list.getTail().value); System.out.println(list); } The first issue is that your
LinkedList class does not have a way of specifying what type of data it should store. You can fix
this using Java Generics. Change the first line of your class to the following: LinkedList .
Confirm that the first line in your main method no longer has an error. On the line that declares
the LinkedList class, add extends List before the bracket that begins the class. The first line in
your class will now have a compile error because LinkedList does not implement the methods
required by the List abstract class. Press Ctrl-i to have IntelliJ insert stubs of these methods.
Ensure that Copy JavaDoc is selected so you get JavaDoc comments which describe the method
requirements, then click OK. Your code should now compile again. Next add fields for the head
and tail. These will be of type Node. Create a getHead method which returns your head field, and
a getTail method which returns your tail field. Run your main method now and you will see that
there is a NullPointerException because the add method does not actually add anything to the
list, so head and tail will always be null. Complete the method boolean add(T value) for which
IntelliJ gave you a stub. You need to create a new node with value to add at the end of the list.
This means you will need to connect it to the old tail and update tail to point to the node you
created. Make sure that you handle the case where the list is empty and both head and tail should
be set to the new node you've created. Note: For the full Map I assignment, add will need to
prevent duplicate values being added to the list and should return true or false based on whether
the value was added or not. For this lab, you can ignore this requirement and simply return true.
Add a toString method to your LinkedList class. It should start at the head of your list and
proceed through all the nodes in a loop, combining the values of each node with a comma
between each and square brackets containing the whole thing. When you run your main method,
the final thing printed should be: [first, middle, last] List.java: /** * Specification for a List
ADT. * @author Shubham Chatterjee * @version 03/07/2019 * @param Type */ public abstract
class List { /** * Appends the specified value to the end of this list. * * @param value T The
value to add * @return boolean True if the value is inserted, false otherwise */ abstract boolean
add(T value); /** * Inserts the specified value at the specified position in this list. * * @param
index Integer The index at which to insert * @param value T The value to insert */ abstract void
add(int index, T value); /** * Removes all of the elements from this list. */ abstract void clear();
/** * Returns true if this list contains the specified element. * * @param o Object The element to
check if present in the list * @return boolean */ abstract boolean contains(Object o); /** *
Returns the element at the specified position in this list. * * @param index Integer The index at
which to insert * @return T */ abstract T get(int index); /** * Get the list entry corresponding to
the value provided in the parameter. * @param o to search for * @return T matching data in the
list */ abstract T get(Object o); /** * Removes the element at the specified position in this list. *
Returns the element from the list or null if index is invalid. * * @param index the index of the
element to be removed * @return the element previously at the specified position or null */
abstract T remove(int index); /** * Removes the first occurrence of the specified element from
this * list, if it is present. * If this list does not contain the element, it is unchanged. * Returns
true if this list contained the specified element * (or equivalently, if this list changed as a result
of the call). * * @param o element to be removed from this list, if present * @return true if this
list contained the specified element */ abstract boolean remove(Object o); /** * Returns true if
this list contains no elements. * * @return true if this list contains no elements */ abstract
boolean isEmpty(); /** * Returns the number of elements in this list. * @return int */ abstract int
size(); /** * Inner class to represent a List node. */ public class Node { T value; Node prev;
Node next; /** * Constructor. * * @param value V The value */ public Node(T value) {
this.value = value; this.prev = null; this.next = null; } } }

More Related Content

PDF
Hi,I have added the methods and main class as per your requirement.pdf
PDF
Given below is the completed implementation of MyLinkedList class. O.pdf
PDF
Please help me to make a programming project I have to sue them today- (1).pdf
PDF
please i need help Im writing a program to test the merge sort alg.pdf
PDF
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
PDF
File LinkedList.java Defines a doubly-l.pdf
PDF
public class MyLinkedListltE extends ComparableltEgtg.pdf
PDF
STAGE 2 The Methods 65 points Implement all the methods t.pdf
Hi,I have added the methods and main class as per your requirement.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
Please help me to make a programming project I have to sue them today- (1).pdf
please i need help Im writing a program to test the merge sort alg.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
File LinkedList.java Defines a doubly-l.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf

Similar to Implementation The starter code includes List.java. You should not c.pdf (20)

PDF
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
PDF
Objective The purpose of this exercise is to create a Linked List d.pdf
PDF
Please and Thank youObjective The purpose of this exercise is to .pdf
PDF
Linked List Objective The purpose of this exercise is to cr.pdf
PDF
Objective The purpose of this exercise is to create a Linke.pdf
PDF
Objective The purpose of this exercise is to create a Linke.pdf
PDF
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
PPT
10-linked-list.ppt
PDF
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
PDF
Write a java class LIST that outputsmainpublic class Ass.pdf
PDF
There are a couple of new methods that you will be writing for this pr.pdf
PDF
import java-util--- public class MyLinkedList{ public static void.pdf
PDF
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
DOCX
Lecture 18Dynamic Data Structures and Generics (II).docx
PDF
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
PDF
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PDF
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
PDF
Can you help me by answering this- The following function defined in c.pdf
PDF
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
PDF
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
Linked List Objective The purpose of this exercise is to cr.pdf
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
10-linked-list.ppt
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
Write a java class LIST that outputsmainpublic class Ass.pdf
There are a couple of new methods that you will be writing for this pr.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Lecture 18Dynamic Data Structures and Generics (II).docx
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Can you help me by answering this- The following function defined in c.pdf
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
Ad

More from maheshkumar12354 (20)

PDF
In a single strand of DNA, the individual nucleotides are covalenty .pdf
PDF
In a recent survey conducted, a random sample of adults 18 years of .pdf
PDF
In a recent survey conducted a random sample of adults 18 years of a.pdf
PDF
In a hypothetical study, a researcher finds that police officers are.pdf
PDF
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdf
PDF
In 2017, President Donald Trump was considering a major increase in .pdf
PDF
In 2021, Lee Jones put the final touches on a product she had worked.pdf
PDF
In 2000 the Vermont state legislature approved a bill authorizing �c.pdf
PDF
Implement the class Linked List to create a list of integers. You ne.pdf
PDF
Implement a program in C++ a by creating a list ADT using the Object.pdf
PDF
Implement a singly linked list as a functional data structure in Kot.pdf
PDF
import java.awt.Color; import java.awt.Dimension; import.pdf
PDF
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdf
PDF
If you were to write an application program that needs to maintain s.pdf
PDF
Imagine that you are using a learning management system (such as Bla.pdf
PDF
Im trying to run make qemu-nox In a putty terminal but it.pdf
PDF
Im posting this again because the answer wasnt correct.Please .pdf
PDF
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdf
PDF
imagine a protein that has been engineered to contain a nuclear loca.pdf
PDF
Im not trying to be rude, but I have had multiple of you experts .pdf
In a single strand of DNA, the individual nucleotides are covalenty .pdf
In a recent survey conducted, a random sample of adults 18 years of .pdf
In a recent survey conducted a random sample of adults 18 years of a.pdf
In a hypothetical study, a researcher finds that police officers are.pdf
In a 1 to 2 page paper, Times New Roman 12, double spaced, APA forma.pdf
In 2017, President Donald Trump was considering a major increase in .pdf
In 2021, Lee Jones put the final touches on a product she had worked.pdf
In 2000 the Vermont state legislature approved a bill authorizing �c.pdf
Implement the class Linked List to create a list of integers. You ne.pdf
Implement a program in C++ a by creating a list ADT using the Object.pdf
Implement a singly linked list as a functional data structure in Kot.pdf
import java.awt.Color; import java.awt.Dimension; import.pdf
Implement two project schedules.BENCHMARKSImplement mechanisms t.pdf
If you were to write an application program that needs to maintain s.pdf
Imagine that you are using a learning management system (such as Bla.pdf
Im trying to run make qemu-nox In a putty terminal but it.pdf
Im posting this again because the answer wasnt correct.Please .pdf
Ignacio enters into a game of chance. A bag of money has twelve $1 b.pdf
imagine a protein that has been engineered to contain a nuclear loca.pdf
Im not trying to be rude, but I have had multiple of you experts .pdf
Ad

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Insiders guide to clinical Medicine.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Computing-Curriculum for Schools in Ghana
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Pre independence Education in Inndia.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Cell Types and Its function , kingdom of life
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Cell Structure & Organelles in detailed.
102 student loan defaulters named and shamed – Is someone you know on the list?
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O7-L3 Supply Chain Operations - ICLT Program
Anesthesia in Laparoscopic Surgery in India
Insiders guide to clinical Medicine.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Computing-Curriculum for Schools in Ghana
Microbial disease of the cardiovascular and lymphatic systems
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pre independence Education in Inndia.pdf
Complications of Minimal Access Surgery at WLH
Pharma ospi slides which help in ospi learning
Cell Types and Its function , kingdom of life
Microbial diseases, their pathogenesis and prophylaxis
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Basic Mud Logging Guide for educational purpose
Cell Structure & Organelles in detailed.

Implementation The starter code includes List.java. You should not c.pdf

  • 1. Implementation The starter code includes List.java. You should not change anything in List.java. Your task will be to create LinkedList.java, make LinkedList use generics and inherit from List, and complete several methods in LinkedList.java. Create LinkedList.java in IntelliJ. Add a main method to LinkedList.java containing the following code. Your program will not compile again. public static void main(String[] args) { LinkedList list = new LinkedList(); System.out.println(list.getHead()); System.out.println(list.getTail()); list.add("first"); list.add("middle"); list.add("last"); System.out.println(list.getHead().value); System.out.println(list.getTail().value); System.out.println(list); } The first issue is that your LinkedList class does not have a way of specifying what type of data it should store. You can fix this using Java Generics. Change the first line of your class to the following: LinkedList . Confirm that the first line in your main method no longer has an error. On the line that declares the LinkedList class, add extends List before the bracket that begins the class. The first line in your class will now have a compile error because LinkedList does not implement the methods required by the List abstract class. Press Ctrl-i to have IntelliJ insert stubs of these methods. Ensure that Copy JavaDoc is selected so you get JavaDoc comments which describe the method requirements, then click OK. Your code should now compile again. Next add fields for the head and tail. These will be of type Node. Create a getHead method which returns your head field, and a getTail method which returns your tail field. Run your main method now and you will see that there is a NullPointerException because the add method does not actually add anything to the list, so head and tail will always be null. Complete the method boolean add(T value) for which IntelliJ gave you a stub. You need to create a new node with value to add at the end of the list. This means you will need to connect it to the old tail and update tail to point to the node you created. Make sure that you handle the case where the list is empty and both head and tail should be set to the new node you've created. Note: For the full Map I assignment, add will need to prevent duplicate values being added to the list and should return true or false based on whether the value was added or not. For this lab, you can ignore this requirement and simply return true. Add a toString method to your LinkedList class. It should start at the head of your list and proceed through all the nodes in a loop, combining the values of each node with a comma between each and square brackets containing the whole thing. When you run your main method, the final thing printed should be: [first, middle, last] List.java: /** * Specification for a List ADT. * @author Shubham Chatterjee * @version 03/07/2019 * @param Type */ public abstract class List { /** * Appends the specified value to the end of this list. * * @param value T The value to add * @return boolean True if the value is inserted, false otherwise */ abstract boolean add(T value); /** * Inserts the specified value at the specified position in this list. * * @param index Integer The index at which to insert * @param value T The value to insert */ abstract void
  • 2. add(int index, T value); /** * Removes all of the elements from this list. */ abstract void clear(); /** * Returns true if this list contains the specified element. * * @param o Object The element to check if present in the list * @return boolean */ abstract boolean contains(Object o); /** * Returns the element at the specified position in this list. * * @param index Integer The index at which to insert * @return T */ abstract T get(int index); /** * Get the list entry corresponding to the value provided in the parameter. * @param o to search for * @return T matching data in the list */ abstract T get(Object o); /** * Removes the element at the specified position in this list. * Returns the element from the list or null if index is invalid. * * @param index the index of the element to be removed * @return the element previously at the specified position or null */ abstract T remove(int index); /** * Removes the first occurrence of the specified element from this * list, if it is present. * If this list does not contain the element, it is unchanged. * Returns true if this list contained the specified element * (or equivalently, if this list changed as a result of the call). * * @param o element to be removed from this list, if present * @return true if this list contained the specified element */ abstract boolean remove(Object o); /** * Returns true if this list contains no elements. * * @return true if this list contains no elements */ abstract boolean isEmpty(); /** * Returns the number of elements in this list. * @return int */ abstract int size(); /** * Inner class to represent a List node. */ public class Node { T value; Node prev; Node next; /** * Constructor. * * @param value V The value */ public Node(T value) { this.value = value; this.prev = null; this.next = null; } } }