Need help writing GarageSet class... you will notice that this class uses a CarD
ID: 3597621 • Letter: N
Question
Need help writing GarageSet class...you will notice that this class uses a CarDataNode class, which I will provide in code at the end of the question.
GarageSet class specs and UML diagram are posted...
UML(very helpful for reference to how project is overall)
*GarageSet
*Must at least have head. You may choose to add a tail
*Should be able to add Nodes (checkIn) and remove nodes (checkOut, using both a String and an index)
i.checkIn and checkOut are also responsible for ensuring the node’s checkIn/checkOut field update appropriately!
ii.Duplicates are not allowed in a set!
*GarageSet’s toString is to be used when displaying the GarageSet on the garage display frame
*GarageSet should be serializable and is responsible for saving itself/loading itself upon program start using the two static methods loadGSData() and saveGSData()
---------------------------------------------------------------------------------------------------------------------------------------------------------
CarDataNode class code...
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;
}
}
C Garage Set (default package) GarageExitBag) o addNodeToBag(CarDataNode):void o dumpOutputFile):void serialVersionulD: long Garageset) o getHeadNode:CarDataNode o checknCar(CarDataNode)void o checkoutCar(int) CarDataNode o checkoutCar(String) CarDataNode OloadGSData):GarageSet o toString0 String -head 0..1 0 C CarDataNode (default package) ad o seriaVersionUD long saveGSData(GarageSet)void licensePlateNumber String a checkin: Date o checkOut Date CarDataNode(String) o getLPN) String o getNext):CarDataNode o checkin)void 0.1 o getCheckin) Date o getCheckOut().Date o addNodeAfter(CarDataNode):void o removeNodeAfter(CarDataNode):void o equals (CarDataNode):boolean findNodeWithData(CarDataNode,String):CarDataNodeey -prev OgetNodeAtindex(CarDataNode,int) CarDataNode otoString):StringExplanation / Answer
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;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.