Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help makng CarDataNode class. My code so far is given below... *CarDataNode

ID: 3596003 • Letter: N

Question

Need help makng CarDataNode class. My code so far is given below...

*CarDataNode specifications (also UML)

*CarDataNode is a doubly linked list node

*It must implement addNodeAfter and toString in a fashion similar to the Book’s ADT/Class Demo Code

i.removeNode removes the calling node from the list!

*checkIn is used to set the Date checkIn to the current time

*checkOut is used to set the Date checkOut to the current time

*equals is only concerned with checking if the license plates between two nodes are the same

*Two static methods are specified

i.Finding a node with a given license plate – takes two arguments, a node to start searching at and the string

ii.Getting a node with a given index – takes two arguments, a node to start searching at and the index of the node to return

*Should be serializable!

import java.util.Date;

-------------------------------------------------------------------------------------------------------------------------------------------------------

My code so far...

public class CarDataNode {

private long serialVersionUID;

private String licensePlateNumber;

private Date checkIn;

private Date checkOut;

public CarDataNode(String cdn){

}

public String getLPN(){

}

public CarDatNode getNext(){

}

public void checkIn(){

}

public void checkOut(){

}

public Date getCheckIn(){

}

public Date getCheckOut(){

}

public void addNodeAfter(CarDataNode addCar){

}

public void removeNodeAfter(CarDataNode reCar){

}

public boolean equals(CarDataNode eqCar){

}

}

dum pout -head 0..1

Explanation / Answer

Assumption : List that is used for implementing linked list is "cdnList"

CarDataNode.java

import java.io.Serializable;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

public class CarDataNode implements Serializable {

private long serialVersionUID;

private String licensePlateNumber;

private Date checkIn;

private Date checkOut;

public CarDataNode(String cdn){

licensePlateNumber=cdn;

checkIn=new Date();

checkOut=new Date();

}

public String getLPN(){

return licensePlateNumber;

}

public CarDataNode getNext(){

CarDataNode cdn=new CarDataNode("");

return cdn;

}

public void checkIn(){

checkIn=new Date();

}

public void checkOut(){

checkOut=new Date();

}

public Date getCheckIn(){

return checkIn;

}

public Date getCheckOut(){

return checkOut;

}

public void addNodeAfter(CarDataNode addCar){

for(int i=0;i<cdnList.size();i++){

//iterate for loop through LinkedList

if(cdnList.get(i).equals(addCar)){

//check the position of the given node by using equals method

CarDataNode addCarNext=new CarDataNode("");

cdnList.add(i+1, addCarNext);

//create new node and add to list at the next index of the given node.

return;

}

}

}

public void removeNodeAfter(CarDataNode reCar){

for(int i=0;i<cdnList.size();i++){

//iterate for loop through LinkedList

if(cdnList.get(i).equals(reCar)){

//check the position of the given node by using equals method

cdnList.remove(i);

//remove the item from the list at the index of the given node.

return;

}

}

}

public boolean equals(CarDataNode eqCar){

if(this.licensePlateNumber.equals(eqCar.licensePlateNumber)){

return true;

}

return false;

}

public static CarDataNode findNodeWithData(CarDataNode cdn,String lpn){

for(int i=0;i<cdnList.size();i++){

if(cdnList.get(i).equals(cdn)){

if(cdnList.get(i).licensePlateNumber.equals(lpn)){

return cdnList.get(i);

}

}

}

return null;

}

public static CarDataNode getNodeAtIndex(CarDataNode cdn,int index){

for(int i=0;i<cdnList.size();i++){

if(cdnList.get(i).equals(cdn)){

if(i>index){

return null;

}

else{

return cdnList.get(index);

}

}

}

return null;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote