CompSci 307
Spring 2019
Software Design and Implementation

Working with Abstraction: Inheritance and Polymorphism

The goal of this lab is to help you to understand how to design abstractions by studying an existing hierarchy and then practice creating your own inheritance hierarchy and using it polymorphically within a collection.

Getting Started

For this lab exercise, work together with someone else in the class (for example your partner for the Game project):

Discussion

Use Gitlab's markdown format to summarize the group's discussion, not simply write direct answers to the questions, in the file called DISCUSSION.md that is included with the example code. IntelliJ includes a markdown editor that provides a preview or here is a web-based editor that provides similar functionality and can be shared like Google Docs.

Start by considering this Overview of Java's collection classes, which includes some design goals and links to the documentation as well. If there is something you like or dislike or something your learned about design during the discussion, make sure to back it up with a specific example. During your study, feel free to search the Internet for other resources beyond the Java documentation.

Use the following questions to guide your discussion:

Identify, Implement, and Use Abstraction

Consider the following problem specification:

A parking garage provides a fixed number of parking spaces for vehicles and must maintain information about the vehicles that are currently in the parking garage so it can report the number of spaces available and the current value. A parking garage must provide publicly available functions to be called when a vehicle enters the garage and when a vehicle leaves the garage. Additionally, the garage must provide publicly available functions that report the capacity of the garage, the number of available spaces in the garage, and the total money collected. The parking fee is a flat rate that is collected when a vehicle leaves the parking garage.

Currently, there are three distinct types of vehicles, cars, low-emission cars, cargo trucks. Every vehicle has a license number consisting of letters and/or numbers and the number of spaces it occupies. Cars have a passenger capacity (i.e., the number of passengers). Trucks have a gross vehicle weight it can transport. Cars take up one space, while trucks take up a number of spaces that is their gross weight divided by 10,000. Cars are charged a rate of $8, low-emission cars are charged half that rate, and trucks are charged $10 per 10,000 pounds of gross weight.

The company wants to be able to sort its parking garages based on their current worth.

Note, tracking which specific spaces are occupied within the garage is beyond the scope of this exercise, just assume there is always room to fit another vehicle of any type until the garage runs out of enough available spaces.

Before starting to code, list the classes you think you will need to implement this program along with only their public method signatures (and especially NOT their instance variables). In reality, this is what an abstraction is within your program: a set of methods available to help solve your problem. Given what we know now, that can either be a superclass or interface, but we will continue to learn more ways to model higher level concepts during the semester. For each public method, note a feature in the problem specification you think it will help to implement.

Implement those methods you planned. If you are confident about what will be your super- and subclasses, then feel free to implement them directly. If you feel more comfortable implementing it directly as modes and then refactoring it that is fine as well. Create a main method that creates at least three garages with different sets of cars and prints out the value of each in sorted order.

After you are confident the code is complete, compare the result to your plan. Explain your reasoning for any of the following in your DISCUSSION file:

Submission

At the end of class, use Gitlab's Merge Request to submit your group's answers to the discussion questions above and your code to the original organization repository. Make sure the NetIDs of everyone in the group are in the title of your Merge Request and in the markdown file.