Lab 6, CSC 203 - Inheritence

In this lab you will explore some aspects of inheritance in Java. In the first part, you will refactor a provided solution which implements a simple calculator to gain experience with inheritance. In the second part, you will explore the notion of "equality" in Java.

Objectives

Given Files

Retrieve the files provided for this lab here:

Refactoring using Inheritance

In the calculator directory is a solution for a simple calculator (with support for variables). For this part of the lab you will modify this solution to refactor common functionality out of some of the classes into a common class.

Many of the expressions are what we would typically call binary expressions. In particular, AddExpression, DivideExpression, MultiplyExpression, and SubtractExpression each have very similar behavior. To see this clearly, compare AddExpression.java and SubtractExpression.java. In fact, let's compare them using diff to see just how similar they are.

diff AddExpression.java SubtractExpression.java

To refactor this common behavior, follow the steps below.

Equality

Examine the provided files in the equality directory.

For this part, you must implement equals and hashCode for the appropriate objects in order for all test cases to pass.

For the CourseSection class, you must implement equals and hashCode in long form (i.e., you must program all computations explicitly). Be sure to handle null values.

For the Student class, you must implement equals and hashCode using the appropriate methods of java.util.Objects.

Submission

This lab is due in approximately a week and a half (either Wednesday 11/1 or Thursday 11/2, depending on your section).

Be sure to commit the code by the due date. Your instructor reserves the right to run further tests on your code. Demonstrate your working program to your instructor. Be prepared to show your source code. (Partial credit available up to instructor discretion).