Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

What is an impairment test? What is its purpose?

Answered: 1 week ago

Question

Question What is the advantage of a voluntary DBO plan?

Answered: 1 week ago