!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> CS 112: Introduction to Computer Science II

Design and development of significantly sized software using top-down design and bottom-up implementation. Dynamically allocated data, object-oriented programming, architecture of memory, basics of language translation, and basics of algorithm analysis. Development of simple graphical user interfaces. Prerequisite: CS 110 (grade of C or better).

Lab 4 - Polymorphism and Inheritance - (50 points)



Due date: 3/30/2016 at 11:59pm

Objectives



  • Use polymorphism and inheritance in Java
  • Create classes and respective methods using UML diagram
Create a directory called lab4.

Create a Vehicle Inventory System



For the following UML diagram, create a vehicle inventory system. Here are a few reminders about UML notation:

  • If the class name is in ITALICS, then the class is an abstract class
  • If a data attribute is underlined, then the attribute is a static member of the class
  • The arrows indicate inheritance relationships between classes


Create the Vehicle Database



Create a driver class called VehicleDatabase. This class will contain an array of type Vehicles, that will store the various vehicles in the database. Here are the requirements for the project.

  • The driver class will read in values from an input file that is passed to the program as a command line argument. The input file must contain at least 15 vehicles (Use a smaller input file for initial testing). The input file should be formatted as follows:
    • The first line of the file should contain the number of elements/rows in the file
    • Each row of the file should contain information for one vehicle (Sedan, MotorCycle, Truck, etc.)
    • The first field in each row should specify the kind of vehicle (Bicycle, MotorCycle, etc.) followed by the appropriate order of elements
    • Here is a sample input file
    • 2
      Truck, Toyota, 4, 10.0, 4, Tundra, 4, 3265, Pickup
      Bicycle, Trek, 2, Skye SLX, 10, 110, true, true 
      				   
  • For each class, implement the appropriate getters/setters for each data attribute in the class
  • For each class, implement a toString method and a getClassName method. Override these methods in derived classes as necessary.
  • Use the numVehicles attribute to keep a track of the total number of vehicles in your database.
  • In your driver class, create a menu that allows a user to do the following:
    • Display the contents in the vehicle database - Display a list of all the vehicles in the database along with all their attributes
    • Print a list of a class of vehicles. Ask the user to choose a class of vehicles to display the information for. For example, you should be able to print only a list of all the Sedans in the system.
    • Print a sorted list of all the vehicle in the database that can be sorted based on their manufacturer name or their number of wheels (numWheels). Ask the user to specify how they would like to sort the vehicles in the database. Use selection sort.
    • Search for a specific vehicle by make. For the search operation, make sure to use binary search.

Submitting the assignment



  • Create a directory called (lab4), copy all the java files and the README into the directory and submit your assignment.
  • You can resubmit the assignment as many times as you want. It will upload a new copy of the files to the SVN repository. We will only grade the one that is closest to 11:59pm on the due date.