Question
How do I search for the Brand Chevrolet in the collection in Java? Same with Model Sportscar? It's at the end of the code. public
How do I search for the Brand "Chevrolet" in the collection in Java? Same with Model "Sportscar"? It's at the end of the code.
public class CarsCollection { /******************************************************************** * ATTRIBUTES * ******************************************************************/ private String name; private Cars[] cars; private int numCars; /******************************************************************** * CONSTRUCTORS * ******************************************************************/ // all necessary parameters for attributes public CarsCollection(String name_, int size) { this.name = name_; cars = new Cars[size]; numCars=0; }
// missing collection size public CarsCollection(String name_) { this.name = name_; cars = new Cars[50]; numCars=0; }
// missing collection name public CarsCollection(int size) { this.name = "My car collection"; cars = new Cars[size]; numCars=0; }
// no initial parameters public CarsCollection() { cars = new Cars[50]; numCars=0; } /******************************************************************** * GET and SET METHODS * ******************************************************************/ // return a car given the index public Cars getCars(int index) { return cars[index]; } // return the remaining space available in the cars array public int spaceAvailable() { return cars.length-numCars; } // return the number of cars in the array public int getNumComics() { return numCars; }
/******************************************************************** * OUTPUT METHODS * ******************************************************************/ // print the entire collection, with title and summary information public void printCollection() { System.out.println(" Collection: "+this.name+" "); System.out.println("--------------------------------------------"); for (int i = 0; i < numCars; i++) { System.out.println((i+1)+": "+this.getCars(i).toString()); } System.out.println(numCars+" in collection."); System.out.println("--------------------------------------------"); } // print a summary of the collection public void printSummary() { for (int i = 0; i < numCars; i++) { System.out.println(this.getCars(i).description()); } }
public void SearchByBrand() { } public void SearchByModel() { } /******************************************************************** * OTHER METHODS * ******************************************************************/
public void addCars(Cars newCars) { cars[numCars] = newCars; numCars++; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started