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

I have this code and i need to be able to use this code so that on the carLinked

ID: 3569184 • Letter: I

Question

I have this code and i need to be able to use this code so that on the carLinked list it works istead of giving me an error when i try to say car.getMake() it says that the car variable cant be found. Also i need to somehow combine the carnode class witht the car class.

The Car class

public class Car
{
private String name;
private String make;
private String color;
private double listPrice;
private double priceSold;
private double commission;
private int year;
private double mileage;
public Car(String name, String make, String color, double listPrice,
double priceSold, double commission, int year, double mileage) { //Constructor
super(); //calls constructor
this.name = name; //reference to name
this.make = make; //reference to make
this.color = color; //refrernce to color
this.listPrice = listPrice; //reference to listPrice
this.priceSold = priceSold; //reference to priceSold
this.commission = commission; //reference to commision
this.year = year; //reference to year
this.mileage = mileage; //reference to mileage
}
public String getName() { //string get name
return name; //return
}
public void setName(String name) { //set name
this.name = name; //reference
}
public String getMake() { //string get make
return make; //return
}
public void setMake(String make) { //get make
this.make = make; //reference
}
public String getColor() { //string get color
return color; //return
}
public void setColor(String color) { //set color
this.color = color; //reference
}
public double getListPrice() { //get list price
return listPrice; //return
}
public void setListPrice(double listPrice) { //set list price
this.listPrice = listPrice; //reference
}
public double getPriceSold() { //get sold price
return priceSold; //return
}
public void setPriceSold(double priceSold) { //set sold price
this.priceSold = priceSold; //reference
}
public double getCommission() { //get commision
return commission; //return
}
public void setCommission(double commission) { //set commision
this.commission = commission; //reference
}
public int getYear() { //get year
return year; //return
}
public void setYear(int year) { //set year
this.year = year; //reference
}
public double getMileage() { //get mileage
return mileage; //return
}
  
public void setMileage(double mileage) { //set mileage
this.mileage = mileage; //reference
}
  
@Override
public String toString() {
return "Car [name=" + name + ", make=" + make + ", color=" + color
+ ", listPrice=" + listPrice + ", priceSold=" + priceSold
+ ", commission=" + commission + ", year=" + year
+ ", mileage=" + mileage + "]";
}
}//end class

The CarLinked Class, The car.getMake() and stuff does not work becuase it says the car variable cannot be found.

public class CarLinkedList
{
private CarNode start;
private int listCount;
public CarLinkedList(CarNode carNode) //constructor
{
start = carNode;
listCount = 1;
}
public CarLinkedList() //constructor
{
start = null;
listCount = 0;
}
public void add(Car car) //add
{
if(start==null)
{
start=new CarNode(car); //new car
return;
}//end if
CarNode current = start;
CarNode temp=new CarNode(car);
while(current.getNext() != null)
{
current = current.getNext();
}//end while
current.setNext(temp);
listCount++;
}
public boolean remove(int index) //remove
{
if(index < 1 || index > size())
return false;
CarNode current = start;
for(int i = 1; i < index; i++)
{
if(current.getNext() == null)
return false;
current = current.getNext();
}//end if
current.setNext(current.getNext().getNext());
listCount--;
return true;
}
public String getName()
{
return car.getName();
}
public String getMake()
{
return car.getMake();
{
public String getColor()
{
return car.getColor();
}
public double getListPrice()
{
return car.getListPrice();
}
public double getCommission()
{
return car.getCommission();
}
public int getYear()
{
return car.Year();
}
public double getMileage()
{
return car.getMileage();
}
public int size() // size
{
return listCount; //return
{
public void display() //display
{
CarNode current = start;
while(current != null)
{
System.out.println(current.getCar().toString());
current = current.getNext();
}//end while
}//end main   
}//end class

The carnode Class. I need to combine this class and the car class please.

public class CarNode
{
CarNode next;
Car car;
public CarNode(Car _car)
{
next = null;
car = _car;
}
public CarNode(Car _car, CarNode _next)
{
next = _next;
car= _car;
}
public CarNode getNext() { //get next
return next; //return
}
public void setNext(CarNode next) { //set Next
this.next = next; //reference
}
public Car getCar() { //gets car
return car; //return car
}
public void setCar(Car car) { //set car
this.car = car; //reference
}
}//end main

Explanation / Answer

package car;

public class CarLinkedList
{
private CarNode start;
private int listCount;
Car car=new Car();
public CarLinkedList(CarNode carNode) //constructor
{
start = carNode;
listCount = 1;
}
public CarLinkedList() //constructor
{
start = null;
listCount = 0;
}
public void add(Car car) //add
{
if(start==null)
{
start=new CarNode(car); //new car
return;
}//end if
CarNode current = start;
CarNode temp=new CarNode(car);
while(current.getNext() != null)
{
current = current.getNext();
}//end while
current.setNext(temp);
listCount++;
}
public boolean remove(int index) //remove
{
if(index < 1 || index > size())
return false;
CarNode current = start;
for(int i = 1; i < index; i++)
{
if(current.getNext() == null)
return false;
current = current.getNext();
}//end if
current.setNext(current.getNext().getNext());
listCount--;
return true;
}
public String getName()
{
return car.getName();
}
public String getMake()
{
return car.getMake();
}
public String getColor()
{
return car.getColor();
}
public double getListPrice()
{
return car.getListPrice();
}
public double getCommission()
{
return car.getCommission();
}
public int getYear()
{
return car.getYear();
}
public double getMileage()
{
return car.getMileage();
}
public int size() // size
{
return listCount; //return
}
public void display() //display
{
CarNode current = start;
while(current != null)
{
System.out.println(current.getCar().toString());
current = current.getNext();
}//end while
}//end main   
}//end class

package car;

public class Car
{
private String name;
private String make;
private String color;
private double listPrice;
private double priceSold;
private double commission;
private int year;
private double mileage;
public Car(){
  
}
public Car(String name, String make, String color, double listPrice,
double priceSold, double commission, int year, double mileage) { //Constructor
super(); //calls constructor
this.name = name; //reference to name
this.make = make; //reference to make
this.color = color; //refrernce to color
this.listPrice = listPrice; //reference to listPrice
this.priceSold = priceSold; //reference to priceSold
this.commission = commission; //reference to commision
this.year = year; //reference to year
this.mileage = mileage; //reference to mileage
}
public String getName() { //string get name
return name; //return
}
public void setName(String name) { //set name
this.name = name; //reference
}
public String getMake() { //string get make
return make; //return
}
public void setMake(String make) { //get make
this.make = make; //reference
}
public String getColor() { //string get color
return color; //return
}
public void setColor(String color) { //set color
this.color = color; //reference
}
public double getListPrice() { //get list price
return listPrice; //return
}
public void setListPrice(double listPrice) { //set list price
this.listPrice = listPrice; //reference
}
public double getPriceSold() { //get sold price
return priceSold; //return
}
public void setPriceSold(double priceSold) { //set sold price
this.priceSold = priceSold; //reference
}
public double getCommission() { //get commision
return commission; //return
}
public void setCommission(double commission) { //set commision
this.commission = commission; //reference
}
public int getYear() { //get year
return year; //return
}
public void setYear(int year) { //set year
this.year = year; //reference
}
public double getMileage() { //get mileage
return mileage; //return
}
  
public void setMileage(double mileage) { //set mileage
this.mileage = mileage; //reference
}
  
@Override
public String toString() {
return "Car [name=" + name + ", make=" + make + ", color=" + color
+ ", listPrice=" + listPrice + ", priceSold=" + priceSold
+ ", commission=" + commission + ", year=" + year
+ ", mileage=" + mileage + "]";
}
}//end class