This is for a assignment in class and I am having trouble with using My car objects in my link List. The car class has two instance variables (make, price). How would I place the variables into the node class.
public class CarList {
private CarNode head = null;
private CarNode tail = null;
private int counter = 0;
public CarList() {
head = null;
}
public int getSize() {
return counter;
}
public boolean isEmpty() {
if(counter < 1) {
return true;
}
else {
return false;
}
}
/**public CarNode firstNode() {
return head;
}
public CarNode lastNode() {
return tail;
}
public CarNode getNode(int target) {
CarNode pre;
pre = head;
while(pre.next != null) {
pre = pre.next;
if(pre.data == target) {
return pre;
}
}
return null;
}**/
public void insert (String target) {
if(head==null || target < head.data) {
insert_at_head(target);
return;
}
CarNode pre = head;
while(pre.next != null && target > (pre.next).data) {
pre = pre.next;
CarNode newNode = new CarNode(target);
newNode.next = pre.next;
pre.next = newNode;
}
}
}
//The CarNode Class
class CarNode {
Car data;
CarNode next;
CarNode pre;
public CarNode(Car entry) {
this.data = entry;
next = null;
pre = null;
}
}
//Car Class
public class Car {
int Price;
String Make;
public Car(int pennies, String m) {
this.Price = pennies;
this.Make = m;
}
public int getPrice() {
return Price;
}
public String getMake() {
return Make;
}
public void setPrice(int p) {
Price = p;
}
public void setMake(String m) {
Make = m;
}
}