Here is my problem. When I use addCar(carobject), it says I'm making a static reference to a non-static method. How do I call the method in the main method? I want to be able to call the method addcar() with my object in the parenthesis. It appears to me as if it should work.
package Lab2;
/*********************************************************************
//Race.java
//
//Race class defines what the race object is
//and what it can do.
//********************************************************************
*/
public class Race {
public double distance;
public String raceType;
public Car[] carsEntered = new Car[3];
final int DEFAULTNUMBEROFCARS = 3;
public static void main(String[] args) {
int carCount = 0;
String winner;
Car myCar = new Car("Chase", 75);
Car ProfCar = new Car("Prof. Harms", 85);
Car JeffCar = new Car("Jeff Gordan", 100);
addCar(myCar);
}
/**
* Changes the distance of the race.
*/
public void changeDistace(double newDistance) {
distance = newDistance;
}
/**
* Changes the Type of the race.
*/
public void changeRaceType(String newRaceType) {
raceType = newRaceType;
}
/**
* Adds a new car to the Race.
*/
public void addCar(Car newCar) {
boolean carPlaced = false;
for(int i=0; i<DEFAULTNUMBEROFCARS;i++) {
if(carPlaced == false) {
if(carsEntered[i] == null) {
carsEntered[i] = newCar;
carPlaced = true;
}
}
}
}
public String getRaceType() {
return raceType;
}
/**
* Prints the cars in the race.
*/
public void getCarsEntered() {
for(int i=0;i<carsEntered.length; i++) {
System.out.println("Owner: " + carsEntered[i].getOwner());
}
}
}