Project 1: Classes, Inheritance, and Abstraction

(Return to homepage)

In Project 1, we'll explore how class hierarchies, abstraction, and interfaces make up aspects of Object-Oriented design.

The program we'll be writing will simulate a little world with interactive buildings, like hotels and restaurants, that share common interfaces but have individually unique behaviors. Buildings are hierarchical in several ways, such as by location (country, city, street) or by people (owner, company, renter). As a real-world software example, when using Yelp to find restaurants, filters like price, location, and operating hours are used to "traverse" the branches of this imaginary hierarchy until dinner is found.

Your task is to implement a pre-designed class hierarchy of interactive buildings. All buildings share some common properties - for example, all buildings have a location (Building::getLocation) and all stores sell products (Store::getProducts). Buildings also have unique properties, depending on their type - for example, hotels are rentable (Rentable::registerRental) while homes are not.

This explainer document (and future explainers) will be less thorough than the Project 0 explainer. The implied meaning of each method implementation is reflected by their names and corresponding unit tests. Learning how to analyze code and the intentions of the original developer is a skill that will benefit you greatly when contributing to an existing project (as opposed to starting from scratch).

Ready? Of course you are. Get the Project 1 starter code here! (jUnit dependencies included)

The project code should work out-of-the-box for IntelliJ (running and debugging), but if you're having trouble getting it working, try these IntelliJ setup instructions.

Interfaces

Classes

lib.Pair: Generic container class for storing two variables: left and right. The two variables can be different types. Commonly used for associating two values, such as a name (String) and a number (int).

world.Building: Top-level abstract class describing a building. A building has a String location.

New Toys

As part of Project 1, you'll be exposed to several Java standard library data structures that you can take advantage of in your program. As a "client" of the Java libraries, you are generally not concerned with underlying implementation - instead, you should focus on understanding the interface provided. Below is a brief description of some of the library classes you may use; there are some examples present in the starter code as well.

When something is iterable, it supports the Iterable interface and can supply an Iterator. Something which is Iterable will support the for each loop construct. For example, the snippet below iterates over all keys of a HashMap<String, Integer> named this.supplies:

for (String item : this.supplies.keySet()) {
    Integer quantity = this.supplies.get(item);
    // do something
}

Running Your Code

As this project has quite a few moving parts, it will take some effort to get the entire project to compile, and IntelliJ sometimes won't run the test suite if there are project errors. Thus, the project is optionally split into two parts:

Phase 1: Implement Supermarket and Restaurant. Tested by test.Phase1Evaluation.

Phase 2: Implement Home and Hotel. Tested by test.Phase2Evaluation.

Phase 1 should be completed before Phase 2, so you can test Phase 1 with the run script runPhase1.sh and Phase 2 with the script runPhase2.sh (which actually includes a complete integration test, involving Phase 1). Alternatively, if you enjoy the IntelliJ debugging experience, write all the necessary method stubs to get the project to compile. As always, .bat scripts are included for Windows, too.

A run script for the entire project test suite is included as run.bat (Windows) or run.sh (Mac/Linux). This will compile your entire project and produce a run report with your estimated grade. Your entire project must compile for the script to work; the phases will not be individually graded, so you must submit a project that will fully compile.

Submission Instructions

See the submissions page for details. Have questions or need help? Post on Piazza!

Critical Analysis Questions

These questions aren't graded, but are similar to those you may see on an exam. You are welcome to discuss these with classmates offline on on Piazza.

(Return to homepage)