SlideShare a Scribd company logo
1 of 11
Download to read offline
How do I fix it in java?
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoSuchElementException {
if(isEmpty()){
throw new NoSuchElementException("The list is empty");
}
if(length == 1){
first = null;
last = null;
iterator = null;
}
else{
if(iterator == first){
iterator = null;
}
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if(isEmpty()){
throw new NoSuchElementException("The list is empty");
}
if(length == 1){
first = null;
last = null;
iterator = null;
}
else{
if(iterator == last){
iterator = null;
}
last = last.prev;
last.next = null;
}
length--;
}
/**
* removes the element referenced by the iterator
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void removeIterator() throws NullPointerException {
if(iterator != null){
if(iterator == first){
first = first.next;
}else{
Node prev = first;
while(prev.next != iterator){
prev = prev.next;
}
prev.next = iterator.next;
if (iterator == last){
last = prev;
}
}
iterator = null;
}else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* places the iterator at the first node
* @postcondition
*/
public void positionIterator(){
iterator = first;
}
/**
* Moves the iterator one node towards the last
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void advanceIterator() throws NullPointerException {
if (!offEnd()){
iterator = iterator.next;
}else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Moves the iterator one node towards the first
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void reverseIterator() throws NullPointerException {
if(iterator != first && iterator != null){
Node prev = first;
while (prev.next != iterator){
prev = prev.next;
}
iterator = prev;
}
}
public void clear() {
first = null;
last = null;
iterator = null;
length = 0;
}
public String toString() {
StringBuilder result = new StringBuilder();
Node temp = first;
while (temp != null){
result.append(temp.data + " ");
temp = temp.next;
}
return result.toString() + "n";
}
@SuppressWarnings("unchecked") //good practice to remove warning here
@Override
public boolean equals(Object obj) {
return false;
}
/**CHALLENGE METHODS*/
public void spinList(int numMoves) throws IllegalArgumentException{
}
public LinkedList altLists(LinkedList list) {
return null;
}
}
.
LabProgram.java
java.lang.NullPointerException
t java.util.Scanner; c class LabProgram { ublic static void main(String[] args) { LabProgram lab
= new LabProgram(); // Make and display list LinkedList Integer > list = new LinkedList
langlerangle() ; for (int i=1;i<4;i++ ) { list.addLast (i); } System.out.print("Created list: " +
list.toString()); // toString() has In System.out.println("list.offEnd(): " + list.offEnd());
System.out.println("list.positionIterator()"); list.positionIterator();
System.out.println("list.offEnd(): " + list.offEnd()); System.out.println("list.getIterator(): " +
list.getIterator()); System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.getIterator(): " + list.getIterator());
System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.getIterator(): " + list.getIterator()); System.out.println("list.
reverseIterator()"); list.reverseIterator(); System.out.println("list.getIterator(): " +
list.getIterator()); System.out.println("list.addIterator(42)"); list.addIterator (42);
System.out.println("list.getIterator(): " + list.getIterator()); System.out.print("list.tostring(): " +
list.tostring()); System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.addIterator(99)"); list.addIterator(99); System.out.print("list.toString(): "
+ list.toString()); System.out.println("list.removeIterator()"); list. removeIterator();
System.out.print("list.toString(): " + list.toString()); System.out.println("list.offEnd(): " +
list.offEnd()); System.out.println("list.positionIterator()"); list.positionIterator();
System.out.println("list.removeIterator()"); list.removeIterator();
System.out.println("list.offEnd(): " + list.offEnd()); System.out.print("list.tostring(): " +
list.toString()); System.out.println("list.positionIterator()"); list.positionIterator();
System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.removeIterator()"); list.removeIterator();
System.out.print("list.toString(): " + list.toString());

More Related Content

Similar to How do I fix it in javaLinkedList.java Defines a doubl.pdf

I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
arkmuzikllc
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
mckellarhastings
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
shanki7
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
MAYANKBANSAL1981
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 
Exception to indicate that Singly LinkedList is empty. .pdf
  Exception to indicate that Singly LinkedList is empty. .pdf  Exception to indicate that Singly LinkedList is empty. .pdf
Exception to indicate that Singly LinkedList is empty. .pdf
aravlitraders2012
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
arorastores
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
amazing2001
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- {   privat.pdfpublic class CircularDoublyLinkedList-E- implements List-E- {   privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
ChristopherkUzHunter
 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
aptind
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Edwardw5nSlaterl
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
Stewart29UReesa
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 

Similar to How do I fix it in javaLinkedList.java Defines a doubl.pdf (20)

I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
Exception to indicate that Singly LinkedList is empty. .pdf
  Exception to indicate that Singly LinkedList is empty. .pdf  Exception to indicate that Singly LinkedList is empty. .pdf
Exception to indicate that Singly LinkedList is empty. .pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- {   privat.pdfpublic class CircularDoublyLinkedList-E- implements List-E- {   privat.pdf
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
 
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdfpackage com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
package com.java2novice.ds.linkedlist;import java.util.NoSuchEleme.pdf
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 

More from fmac5

How can the info listed here be written into 2�3-page paper with APA.pdf
How can the info listed here be written into 2�3-page paper with APA.pdfHow can the info listed here be written into 2�3-page paper with APA.pdf
How can the info listed here be written into 2�3-page paper with APA.pdf
fmac5
 
hing Match the terms with their definitions. 1. DV technology 2. ref.pdf
hing Match the terms with their definitions. 1. DV technology 2. ref.pdfhing Match the terms with their definitions. 1. DV technology 2. ref.pdf
hing Match the terms with their definitions. 1. DV technology 2. ref.pdf
fmac5
 
help please Identify the step in the innovation process at which the.pdf
help please Identify the step in the innovation process at which the.pdfhelp please Identify the step in the innovation process at which the.pdf
help please Identify the step in the innovation process at which the.pdf
fmac5
 
Hello please help me how to do this project in C and explain to me h.pdf
Hello please help me how to do this project in C and explain to me h.pdfHello please help me how to do this project in C and explain to me h.pdf
Hello please help me how to do this project in C and explain to me h.pdf
fmac5
 
Gordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdf
Gordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdfGordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdf
Gordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdf
fmac5
 
Go to Previous section To Partner or Not to Partner with a Retail Co.pdf
Go to Previous section To Partner or Not to Partner with a Retail Co.pdfGo to Previous section To Partner or Not to Partner with a Retail Co.pdf
Go to Previous section To Partner or Not to Partner with a Retail Co.pdf
fmac5
 

More from fmac5 (20)

how can we anser these following questions and prove which is the an.pdf
how can we anser these following questions and prove which is the an.pdfhow can we anser these following questions and prove which is the an.pdf
how can we anser these following questions and prove which is the an.pdf
 
How can the info listed here be written into 2�3-page paper with APA.pdf
How can the info listed here be written into 2�3-page paper with APA.pdfHow can the info listed here be written into 2�3-page paper with APA.pdf
How can the info listed here be written into 2�3-page paper with APA.pdf
 
hing Match the terms with their definitions. 1. DV technology 2. ref.pdf
hing Match the terms with their definitions. 1. DV technology 2. ref.pdfhing Match the terms with their definitions. 1. DV technology 2. ref.pdf
hing Match the terms with their definitions. 1. DV technology 2. ref.pdf
 
help please Identify the step in the innovation process at which the.pdf
help please Identify the step in the innovation process at which the.pdfhelp please Identify the step in the innovation process at which the.pdf
help please Identify the step in the innovation process at which the.pdf
 
Help in Java We refer to crew members by their ID numbers, which are.pdf
Help in Java We refer to crew members by their ID numbers, which are.pdfHelp in Java We refer to crew members by their ID numbers, which are.pdf
Help in Java We refer to crew members by their ID numbers, which are.pdf
 
Help me make an Elevator pitch using the information below, thank yo.pdf
Help me make an Elevator pitch using the information below, thank yo.pdfHelp me make an Elevator pitch using the information below, thank yo.pdf
Help me make an Elevator pitch using the information below, thank yo.pdf
 
he Fort Ellis city council approved and adopted its fiscal year budg.pdf
he Fort Ellis city council approved and adopted its fiscal year budg.pdfhe Fort Ellis city council approved and adopted its fiscal year budg.pdf
he Fort Ellis city council approved and adopted its fiscal year budg.pdf
 
hello with only using the properties from the right hand side can yo.pdf
hello with only using the properties from the right hand side can yo.pdfhello with only using the properties from the right hand side can yo.pdf
hello with only using the properties from the right hand side can yo.pdf
 
Hello please help me how to do this project in C and explain to me h.pdf
Hello please help me how to do this project in C and explain to me h.pdfHello please help me how to do this project in C and explain to me h.pdf
Hello please help me how to do this project in C and explain to me h.pdf
 
Greenwich Industries entered the Latin American market in the 1950s .pdf
Greenwich Industries entered the Latin American market in the 1950s .pdfGreenwich Industries entered the Latin American market in the 1950s .pdf
Greenwich Industries entered the Latin American market in the 1950s .pdf
 
Gordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdf
Gordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdfGordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdf
Gordon and Colleen Howe� Mini CaseToday is January 1, 2023.pdf
 
Go to Previous section To Partner or Not to Partner with a Retail Co.pdf
Go to Previous section To Partner or Not to Partner with a Retail Co.pdfGo to Previous section To Partner or Not to Partner with a Retail Co.pdf
Go to Previous section To Partner or Not to Partner with a Retail Co.pdf
 
Given the following list of accounts with normal balance, prepare a .pdf
Given the following list of accounts with normal balance, prepare a .pdfGiven the following list of accounts with normal balance, prepare a .pdf
Given the following list of accounts with normal balance, prepare a .pdf
 
Given the following challenges, use append(), extend(), pop(), and i.pdf
Given the following challenges, use append(), extend(), pop(), and i.pdfGiven the following challenges, use append(), extend(), pop(), and i.pdf
Given the following challenges, use append(), extend(), pop(), and i.pdf
 
Given Microsoft�s lackluster performance since 2000, the once domina.pdf
Given Microsoft�s lackluster performance since 2000, the once domina.pdfGiven Microsoft�s lackluster performance since 2000, the once domina.pdf
Given Microsoft�s lackluster performance since 2000, the once domina.pdf
 
Given an array of ints, return true if the number of 1s is greate.pdf
Given an array of ints, return true if the number of 1s is greate.pdfGiven an array of ints, return true if the number of 1s is greate.pdf
Given an array of ints, return true if the number of 1s is greate.pdf
 
give me an example of 6. Additional Plans Specify or re.pdf
give me an example of 6. Additional Plans Specify or re.pdfgive me an example of 6. Additional Plans Specify or re.pdf
give me an example of 6. Additional Plans Specify or re.pdf
 
Give me a substantive comment on this postThe way an organization.pdf
Give me a substantive comment on this postThe way an organization.pdfGive me a substantive comment on this postThe way an organization.pdf
Give me a substantive comment on this postThe way an organization.pdf
 
Give an extensive background of Pick n Pay. This should include info.pdf
Give an extensive background of Pick n Pay. This should include info.pdfGive an extensive background of Pick n Pay. This should include info.pdf
Give an extensive background of Pick n Pay. This should include info.pdf
 
Geoffrey This is very helpful, but I need your guidance to s.pdf
Geoffrey This is very helpful, but I need your guidance to s.pdfGeoffrey This is very helpful, but I need your guidance to s.pdf
Geoffrey This is very helpful, but I need your guidance to s.pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

How do I fix it in javaLinkedList.java Defines a doubl.pdf

  • 1. How do I fix it in java? LinkedList.java: /** * Defines a doubly-linked list class * @author * @author */ import java.util.NoSuchElementException; public class LinkedList { private class Node { private T data; private Node next; private Node prev; public Node(T data) { this.data = data; this.next = null; this.prev = null; } } private int length; private Node first; private Node last; private Node iterator; /**** CONSTRUCTORS ****/ /** * Instantiates a new LinkedList with default values * @postcondition */ public LinkedList() { first = null; last = null; iterator = null; length = 0;
  • 2. } /** * Converts the given array into a LinkedList * @param array the array of values to insert into this LinkedList * @postcondition */ public LinkedList(T[] array) { } /** * Instantiates a new LinkedList by copying another List * @param original the LinkedList to copy * @postcondition a new List object, which is an identical, * but separate, copy of the LinkedList original */ public LinkedList(LinkedList original) { } /**** ACCESSORS ****/ public T getFirst() throws NoSuchElementException { if (isEmpty()){ throw new NoSuchElementException("The list is empty"); } return first.data; } public T getLast() throws NoSuchElementException { if (isEmpty()){ throw new NoSuchElementException("The list is empty"); } return last.data; }
  • 3. /** * Returns the data stored in the iterator node * @precondition * @return the data stored in the iterator node * @throw NullPointerException */ public T getIterator() throws NullPointerException { if (iterator != null){ return iterator.data; }else{ throw new NullPointerException("Iterator is off the end opf the list."); } } /** * Returns the current length of the LinkedList * @return the length of the LinkedList from 0 to n */ public int getLength() { return length; } /** * Returns whether the LinkedList is currently empty * @return whether the LinkedList is empty */ public boolean isEmpty() { return length == 0; } /** * Returns whether the iterator is offEnd, i.e. null * @return whether the iterator is null */
  • 4. public boolean offEnd() { return iterator == null; } /**** MUTATORS ****/ public void addFirst(T data) { Node newNode = new Node(data); if(isEmpty()){ first = newNode; last = newNode; } else{ newNode.next = first; first.prev = newNode; first = newNode; } length++; } public void addLast(T data) { Node newNode = new Node(data); if(isEmpty()){ first = newNode; last = newNode; } else{ last.next = newNode;
  • 5. newNode.prev = last; last = newNode; } length++; } /** * Inserts a new element after the iterator * @param data the data to insert * @precondition * @throws NullPointerException */ public void addIterator(T data) throws NullPointerException{ if(iterator != null){ Node newNode = new Node(data); newNode.next = iterator.next; iterator.next = newNode; if (iterator == first){ first = newNode; } }else{ throw new NullPointerException("Iterator is off the end opf the list."); } } / public void removeFirst() throws NoSuchElementException { if(isEmpty()){ throw new NoSuchElementException("The list is empty"); }
  • 6. if(length == 1){ first = null; last = null; iterator = null; } else{ if(iterator == first){ iterator = null; } first = first.next; first.prev = null; } length--; } public void removeLast() throws NoSuchElementException { if(isEmpty()){ throw new NoSuchElementException("The list is empty"); } if(length == 1){ first = null; last = null; iterator = null; } else{ if(iterator == last){ iterator = null; } last = last.prev; last.next = null; } length--; }
  • 7. /** * removes the element referenced by the iterator * @precondition * @postcondition * @throws NullPointerException */ public void removeIterator() throws NullPointerException { if(iterator != null){ if(iterator == first){ first = first.next; }else{ Node prev = first; while(prev.next != iterator){ prev = prev.next; } prev.next = iterator.next; if (iterator == last){ last = prev; } } iterator = null; }else { throw new NullPointerException("Iterator is off the end opf the list."); } } /**
  • 8. * places the iterator at the first node * @postcondition */ public void positionIterator(){ iterator = first; } /** * Moves the iterator one node towards the last * @precondition * @postcondition * @throws NullPointerException */ public void advanceIterator() throws NullPointerException { if (!offEnd()){ iterator = iterator.next; }else { throw new NullPointerException("Iterator is off the end opf the list."); } } /** * Moves the iterator one node towards the first * @precondition * @postcondition * @throws NullPointerException */ public void reverseIterator() throws NullPointerException { if(iterator != first && iterator != null){ Node prev = first;
  • 9. while (prev.next != iterator){ prev = prev.next; } iterator = prev; } } public void clear() { first = null; last = null; iterator = null; length = 0; } public String toString() { StringBuilder result = new StringBuilder(); Node temp = first; while (temp != null){ result.append(temp.data + " "); temp = temp.next; } return result.toString() + "n"; }
  • 10. @SuppressWarnings("unchecked") //good practice to remove warning here @Override public boolean equals(Object obj) { return false; } /**CHALLENGE METHODS*/ public void spinList(int numMoves) throws IllegalArgumentException{ } public LinkedList altLists(LinkedList list) { return null; } } . LabProgram.java java.lang.NullPointerException t java.util.Scanner; c class LabProgram { ublic static void main(String[] args) { LabProgram lab = new LabProgram(); // Make and display list LinkedList Integer > list = new LinkedList langlerangle() ; for (int i=1;i<4;i++ ) { list.addLast (i); } System.out.print("Created list: " + list.toString()); // toString() has In System.out.println("list.offEnd(): " + list.offEnd()); System.out.println("list.positionIterator()"); list.positionIterator(); System.out.println("list.offEnd(): " + list.offEnd()); System.out.println("list.getIterator(): " + list.getIterator()); System.out.println("list.advanceIterator()"); list.advanceIterator(); System.out.println("list.getIterator(): " + list.getIterator()); System.out.println("list.advanceIterator()"); list.advanceIterator(); System.out.println("list.getIterator(): " + list.getIterator()); System.out.println("list. reverseIterator()"); list.reverseIterator(); System.out.println("list.getIterator(): " + list.getIterator()); System.out.println("list.addIterator(42)"); list.addIterator (42); System.out.println("list.getIterator(): " + list.getIterator()); System.out.print("list.tostring(): " + list.tostring()); System.out.println("list.advanceIterator()"); list.advanceIterator(); System.out.println("list.advanceIterator()"); list.advanceIterator(); System.out.println("list.addIterator(99)"); list.addIterator(99); System.out.print("list.toString(): "
  • 11. + list.toString()); System.out.println("list.removeIterator()"); list. removeIterator(); System.out.print("list.toString(): " + list.toString()); System.out.println("list.offEnd(): " + list.offEnd()); System.out.println("list.positionIterator()"); list.positionIterator(); System.out.println("list.removeIterator()"); list.removeIterator(); System.out.println("list.offEnd(): " + list.offEnd()); System.out.print("list.tostring(): " + list.toString()); System.out.println("list.positionIterator()"); list.positionIterator(); System.out.println("list.advanceIterator()"); list.advanceIterator(); System.out.println("list.advanceIterator()"); list.advanceIterator(); System.out.println("list.removeIterator()"); list.removeIterator(); System.out.print("list.toString(): " + list.toString());