Skip to content

zrplumridge/CSC120-A7

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSC120-A7: Not Your Parent's Method

Outline

In this assignment (Part II of a two-week assignment), we'll dive a little deeper into how to use Inheritance and Method Overriding / Overloading to write parsimonious programs.

We'll start with an expanded version of our class representing a generic Building (Building.java):

Building icon created by Freepik - Flaticon

On top of its previous functionality, our Building class now has several useful new features:

  • Overloaded constructors, adding some flexibility about how Buildings are constructed
  • Various methods for interacting with the building (e.g. enter(), exit(), goUp(), goDown(), and goToFloor(int n)).
  • A handy showOptions() method to tell the user what options are available
  • A few additional class attributes (feel free to explore)

Phase 0: Swapping Out Building.java

First things first: replace the original Building class from A6: Use What Your Parent (Class) Gave You with the expanded version contained in this repo, and make sure that your implementations of House.java, Library.java, and Cafe.java still work as expected.

Phase 1: Overriding Methods

The Building class provides a lot of useful functionality, but some of it doesn't quite work for all three of our Building subclasses. This isn't a problem: we'll just override them! Hint: use super whenever possible to avoid duplicating code!

showOptions()

Since each of the three subclasses have additional options, start by overriding the showOptions() method to reflect the subclass-specific options for House, Library, and Cafe.

goToFloor(int n)

Most Library buildings (and some Houses as well) have elevators, which means it is possible to move between non-adjacent floors in a single action. Override the goToFloor(int n) method to reflect this. Hint: you may want to add a boolean attribute to elevator-friendly classes to indicate whether or not the building has an elevator, and use this in determining whether or not a call to goToFloor(...) is valid.

Phase 2: Overloading Methods

As we see in the Building class, it can often be handy to have multiple versions of a method to handle different types/numbers of input. For this phase, implement at least 2 overloaded methods for each of the subclasses. You may choose to overload only the constructors, or any other methods of your choosing. Please document which methods you overloaded (and why!) in your reflection.md.

Phase 3: CampusMap.java

We'll use the CampusMap class to aggregate many different Buildings together:

Map icon created by Freepik - Flaticon

Expanding on the example in CampusMap.main(...), add at least 10 more of your favorite Smith College buildings.

Kudos (OPTIONAL)

Want to test your programming chops out on a stretch goal that will help prepare you for your final project? See if you can make your map interactive by implementing a loop that enables the user to explore various buildings and make use of their various methods (e.g. moving into a House, checking out a book at the Library or buying a cup of coffee at the Cafe).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%