so I had this java code below which the compiler said couldn't find symbol for my car class so had to create an empty class like this:
public class TrafficQueue {
private Car [] carArray;
private int numberOfcarsInQueue;
public TrafficQueue(int numberOfcarsInQueue){
carArray = new Car[numberOfcarsInQueue];
}
private class Car {} ; // define an empty Car class
public void add(Car car){
carArray[numberOfcarsInQueue] = car;
numberOfcarsInQueue ++;
}
public static void main(String[] args) {
// TODO code application logic here
TrafficQueue queueLane1 = new TrafficQueue(10);
queueLane1.add("Red Chevrolet");
i try to run and i get an error using queuelane1.add("Red Chevrolet")
from my previous knowledge of creating object arrays this is done as:
private Car [] carArray;
then initialised in the constructor as:
carArray = new Car[numberOfcarsInQueue];
but however this does not work until i create a new empty class. my question why do i have to create a new class?
and from my code how i do i add a new car object?