Need help with just a couple of minor errors.
for the lab I am currently doing I have 2 service/class (no clients or application classes).
these are my errors
Car2.java:138: error: not a statement
Cars D = (Car2) car
^
Car2.java:138: error: ';' expected
Cars D = (Car2) car
Can I simply fix them by adding a semi-colon or calling it car instead.
Car2 service class
/**
* Java Car Service class
* @author Blake
* 2/20/2012
*/
/**
* Default constructor.
*/
public class Car2
{
private int yearModel; // The car's year model
private String make; // The car's make
private int speed; // The car's speed
private String license; // The car's license
/**
* Constructor that initializes the model, make and speed of the car.
*
* @param newYearModel - Year Model of the car
* @param newMake - Make of the car
*/
public Car2(int newYearModel, String newMake, String newLicense)
{
yearModel = newYearModel;
make = newMake;
license = newLicense;
speed = 0;
}
/**
* Changes Year Model
* @param yearmodel - new year model
*/
public void setYearModel(int y )
{
yearModel = y;
}
/**
* Accesses Year model
* @return year model of the car
*/
public int getYearModel()
{
return yearModel;
}
/**
* Changes Make
* @param make - new year model
*/
public void setMake(String m)
{
make = m;
}
/**
* Accesses Make
* @return make of the car
*/
public String getMake()
{
return make;
}
/**
*
*
*/
public void setLicense(String l)
{
license = l;
}
public String getLicense()
{
return license;
}
/**
* Changes Speed
* @param speed - new speed
*/
public void setSpeed (int s)
{
speed = s;
}
/**
* Accesses Speed
* @return speed of the car
*/
public int getSpeed()
{
return speed;
}
/**
* Changes Speed
* @param accelerates speed in increments of 5
*/
public void accelerate()
{
speed += 5;
}
/**
* Changes Speed
* @param decelerate speed in increments of 5
*/
public void brake()
{
speed -= 5;
}
/**public String toString()
{
return "yearModel" + yearModel + "make" + make + "license" + license;
}*/
public String toString ()
{
String str = "\nCars in Collection:\n";
if (inUse ==0);
for ( int index =0; index < inUse; index++)
str +=cars [index] + " ";
return str;
}
public boolean equals(Car2 car)
{
if (car instanceof Car2)
Cars D = (Car2) car
(this.newYearModel(), this.newMake(), this.newSpeed(), this.newLicense());
}
}
Carcollection service class
/**
* Java Car Service class
* @author Blake
* 2/20/2012
*/
public class CarCollection
{
private Car2 cars[] ;
private int maxSize =3;
private int currentSize;
private int inUse;
public CarCollection()
{
maxSize = 3;
inUse = 0;
}
public CarCollection(int maxSize)
{
maxSize = maxSize;
inUse = 0;
}
/**public boolean add(int newYearModel, String newMake, String newLicense)
{ boolean success;
if (currentSize < maxSize)
{ Collection collection3 = new Car2(newYearModel, newMake, newLicense);
collection[currentSize] = collection3;
currentSize++;
success = true;
}
else
success = false;
return success;
}*/
/**public boolean remove(String license)
{
boolean found = false;
for (int i=0; i<collection.length && !found; i++)
{ if (license[i] == datatoberemoved)
{ location = i;
found = true;
}
}
if (found)
{ for (string i=location; i<collection-1; i++)
{ license[i] = license[i+1];
}
collection--;*
}
}*/
public int currentSize(int currentSize)
{
return currentSize;
}
public int getCurrentSize()
{
return currentSize;
}
public int setMaxSize(int Maxsize)
{
return MaxSize;
}
public int getMaxSize()
{
return maxSize();
}
public void add(int newYearModel, String newMake , String newlicense)
{
Car2 myCars = new Car2 (newyYear, newMake, newlicense);
cars [inUse]= myCars;
inUse ++;
}
public void remove (String license)
{
boolean success = true;
if (cars.equalsIgnoreCase(Sweet))
{
inUse --;
}
else
success = false;
return success;
}
public String toString ()
{
String str = "Number of cars that are required";
if (collection.length == 0)
str = "\n no cars are required \n:";
for (int index=0; index < collection.length; index++)
str += nums[index];
return str;
}
}