The goal of this project is to implement a program that maintains a searchable database of cars. You will use the following features:
- Interfaces
- Inheritance
- Arrays
For this assignment, you will build a database using the following CSV file: cars.csv. You will then implement a driver class that invokes methods to retrieve required information from the database.
Your grade will depend heavily on the design of your solution. Make sure that all of the requirements are followed and that the remaining components are well-designed and efficient.
For full credit, your solution must use the following design elements.
- You may not use
ArrayList
for any portion of this program. - You may not use
ArrayList
for any portion of this program (REALLY!). - You must implement a base class
Car
. TheCar
class cannot be instantiated. - A
Car
must have at least the following properties:model
(column Model),vehicleClass
(column Veh Class), andpollutionScore
(column Air Pollution Score). Car
must also beComparable
.Car
objects are sorted first by pollution score. If twoCar
objects have the same pollution score then they will be sorted by model.Car
must have two subclasses:GasCar
andGreenCar
.- A
GasCar
is any car that does not have a Fuel of Hydrogen or Electricity. Hybrid cars (e.g., Fuel Gasoline/Electricity) are considered typeGasCar
.GasCar
must have at least the following properties:numberCylinders
(column Cyl) andmpg
(column Cmb MPG). For cars with two values for Cmb MPG the value used should be the first value (to the left of the "/"). - A
GreenCar
is a car with Fuel either Hydrogen or Electricity.GreenCar
will have the propertyfuelType
(column Fuel). This will either be "Hydrogen" or "Electricity". - You must have a
CarList
that maintains a sorted array ofCar
objects. Use thecompareTo
method to sortCar
objects. You may not useArrays.sort
in this method. CarList
will have, at minimum, the following methods. You may add additional helper methods as appropriate.
addCar
- this method takes as input aCar
and inserts it into the array in sorted order. If the array is full it will be resized to accommodate a new item. If twoCar
objects are equal according tocompareTo
they will be sorted in the list in the reverse order in which they appear in the original data file.toString
- returns aString
representation of the entire database. The representation of aGasCar
will look as follows: Model: VOLVO XC 90 Class: standard SUV Pollution Score: 9 MPG: 25 Cylinders: 4 The representation of aGreenCar
will look as follows: Model: FIAT 500e Class: small car Pollution Score: 10 Fuel Type: ElectricitytoStringGreenCars
- returns aString
representation of theGreenCar
objects in the list where the representation for eachCar
is of the following format: Model: BMW i3 BEV Fuel Type: Electricity. Note, the format for this method is different than that of thetoString
method.avgMpg
- takes no parameters and returns the average MPG across allGasCar
objects.avgMpgByPartialModel
- takes as input aString
with a partial model (for example, "Subaru") and returns the average MPG for all cars with a model containing the partial model queryString
. You may use theString
contains
method in your solution for this method.findClassesByCylinders
- takes as input anint
specifying number of cylinders and returns aString[]
containing the vehicle classes with models that have the specified number of cylinders. For full credit, theString[]
will have no repeated elements (each class will only appear once) and the length must be large enough to accommodate only the number of valid elements. The resulting array will be sorted and you may useArrays.sort
for this purpose.findModelsByClassAndMpg
- takes as input a target vehicle class and a minimum MPG and returns aString[]
containing the models of all vehicles of the specified class that have at least the specified combined MPG. TheString[]
may have repeated elements if the same model appears twice in the dataset, but the the length must be large enough to accommodate only the number of valid elements. The resulting array will be sorted and you may useArrays.sort
for this purpose.
- The
main
method will be in a class calledCarDBDriver
. The suggested algorithm for this method is as follows:
- Build a
CarList
object from the file cars.csv. - Print "All Cars:" followed by a newline.
- Print the result of calling
toString
on theCarList
. - Print "Green Cars - Fuel Type:" followed by a newline.
- Print the result of calling
toStringGreenCars
on theCarList
. - Print "Average MPG All:" followed by the result of calling
avgMpg
on theCarList
followed by a newline. The result should be displayed with exactly two digits after the decimal point. - Print "Average MPG Subaru:" followed by the result of calling
avgMpgByPartialModel("SUBARU")
on theCarList
followed by a newline. The result should be displayed with exactly two digits after the decimal point. - Print "Average MPG Toyota:" followed by the result of calling
avgMpgByPartialModel("TOYOTA")
on theCarList
followed by a newline. The result should be displayed with exactly two digits after the decimal point. - Print "Average MPG Ferrari:" followed by the result of calling
avgMpgByPartialModel("FERRARI")
on theCarList
followed by a newline. The result should be displayed with exactly two digits after the decimal point. - Print "Vehicle Classes with 4-Cylinder Cars:" followed by a newline followed by the result of calling
findClassesByCylinders(4)
on theCarList
. For each item in the list returned, print a tab followed by the item followed by a newline. - Print "Vehicle Classes with 6-Cylinder Cars:" followed by a newline followed by the result of calling
findClassesByCylinders(6)
on theCarList
. For each item in the list returned, print a tab followed by the item followed by a newline. - Print "Small SUVs with MPG > 22:" followed by a newline followed by the result of calling
findModelsByClassAndMpg("small SUV", 22)
on theCarList
. For each item in the list returned, print a tab followed by the item followed by a newline. - Print "Small Cars with MPG > 35:" followed by a newline followed by the result of calling
findModelsByClassAndMpg("small car", 35)
on theCarList
. For each item in the list returned, print a tab followed by the item followed by a newline.
- Your output must exactly match the following: p3output.txt All spacing, indentation, and ordering must exactly match the result.
- You may implement classes in addition to those specified.
-
For this assignment, you will submit all Java files you implemented for this program. Your
main
method must be in a fileCarDBDriver.java
. You must also submitCar.java
,CarList.java
,GreenCar.java
, andGasCar.java
. It is expected you will have at least one additional Java file. -
Make sure your code follows all requirements in the Style Guidelines.
-
Follow the instructions in the SVN Guide for submitting your solution by the deadline.
-
Make sure you have submitted your work in an SVN directory:
https://www.cs.usfca.edu/svn/<username>/cs112/project3