******************************************************
Error:
MyCarList.java:19: cannot find symbol
symbol : constructor MyCar(int)
location: class MyCar
mycars = new MyCar(maxSize);
MyCarList Class
**********************************************************
import java.util.Comparator;
import java.util.*;
/**
* Class to represent a collection of cars
* @Jon Reid
* @version 2 - 9/3/10
*/
public class MyCarList implements CarList{
//Define some class vars
private Car[] mycars;
private int currentSize;
private final int maxsize = 100; // assign max array size here, easy to edit later
public MyCarList(int maxSize){
currentSize = 0;
mycars = new Car(maxSize);
}
public boolean add(Car car){
//check if the array is full
if(currentSize == mycars.length){
//we need to expand the array's length to cope
expand();
return false;
}
else if(currentSize < mycars.length){
mycars[currentSize] = car;
currentSize ++;
return true;
}
//safe to add the element and increase currentSize by one
mycars[currentSize++] = car;
return false;
}
public boolean remove(Car car){
boolean result = false;
for(int i = 0; i < mycars.length; i++){
if (mycars[i] == car){
mycars[i] = null;
currentSize--;
result = true;
}
}
return result;
}
public Car find(String regno){
for(int i = 0; i < mycars.length; i++){
if(mycars[i].getRegNo().equals(regno))
return mycars[i];
}
return null;
}
public int sortByRegNo(){
Arrays.sort(mycars, new CompRegNo());
}
public int sortByYear(){
Arrays.sort(mycars, new CompYear());
}
public int sortByPrice(){
Arrays.sort(mycars, new CompPrice());
}
public int sortByModel(){
Arrays.sort(mycars, new CompModel());
}
public void clear(){
mycars= new Car[maxsize];
currentSize = 0;
}
public int size(){
return currentSize;
}
// public void java.util.Iterator<Car> iterator(){
public String toString(){
String contents = ""; //create empty string
for ( int i = 0; i < currentSize; i++){
contents += "\n\nCar: " + i + "\n" + mycars[i].toString() + "\n";
}
return contents;
}
public void expand(){
//declare a tempArray to hold the current array
Car[] tempArray = mycars;
int newSize = mycars.length+5;
//create a new array that is one element larger
mycars = new Car[newSize];
//copy the contents of tempArray into the new store (larger array)
//(note the condition statement 'maxSize-1')
for(int i = 0; i < tempArray.length; i++){
mycars[i] = tempArray[i];
}
}
private void swap(int i, int j){
Car temp = mycars[i];
mycars[i] = mycars[j];
mycars[j] = temp;
}
}
MyCar Class
**********************************************************
import java.util.Comparator;
/**
* Class to represent cars
* @Jon Reid
* @(v1 & 9/3/10)
*/
public class MyCar implements Car{
//object values
String model;
String regNo;
int year;
int price;
//constructor
public MyCar(String theModel, String theRegNo, int theYear, int thePrice){
model = theModel;
regNo = theRegNo;
year = theYear;
price = thePrice;
}
/**
not used
*/
public int compareTo(Car a){
return 1;
}
/**
* Get the car's registration number
* @return the cars model
*/
public String getModel(){
return model;
}
/**
* Get the car's registration number
* @return the cars registration number
*/
public String getRegNo(){
return regNo;
}
public int getYear(){
return year;
}
public int getPrice(){
return price;
}
public void setPrice(int newPrice){
price = newPrice;
}
public boolean match(String thisModel, int thisYear, int thisPrice){
if(thisModel == model && thisYear == year && thisPrice == price){
return true;
}
else{
return false;
}
}
public int getCompCount(){
return 1;
}
public String toString(){
String carString = ("Price: " + price +
" Year : " + year +
" Reg Number : " + regNo +
" Registration : " + model);
return carString;
}
}