CSC220 Lab Number 1
Due: 10:59AM, Tuesday, September 7 (part 1; i.e., Lab 1)
Due: 10:59AM, Tuesday, September 14 (part 2; i.e., Lab 2)
In this lab, you first learn the use of Eclipse with the help
from a teaching assistant and get started on the program described below.
The overall goal is to design two interfaces, one extending the other,
and two classes that respectively implement them.
We wish to design two classes, TwoNames and TwoNamesValue.
The former is for recording two names and the latter is for recording
two names and a value.
-
Each of the two names is a String object and the value is a double object.
-
For each class a constructor is needed that takes as arguments data to be stored.
-
For each field needed are a method for accessing the data and a method for modifying the data.
-
For both of them a method called equals is needed that takes an object of the same type and whether the two objects are equal to each other.
We accomplish the above task by design the following:
-
An interface TwoNamesInt.java for the class TwoNames.java that specifies all the aforementioned methods for TwoNames.java. They are:
-
getNameOne for obtaining the first of the two names;
-
getNameTwo for obtaining the second of the two names;
-
setNameOne for modifying the first of the two names to a given one;
-
setNameTwo for mofidying the second of the two names to a given one;
-
equals for checking equality with another object of type
TwoNamesInt.java;
-
matches for checking whether a given String object is equal to one of the two names;
The code for this interface is already available.
Click the link to the code for TwoNamesInt.java to obtain it.
-
TwoNamesValueInt.java for extending TwoNamesInt.java so as to hold, in addition to the data TwoNamesInt.java specifies to hold, a double value.
The interface has the following methods not defined in TwoNamesInt.java
-
getValue for obtaining the value stored;
-
setValue for modifying the value stored to a given one;
-
equals for checking equality with another object of the same type;
-
matches for checking whether a given double value is equal to the one stored.
-
TwoNames.java for implementing TwoNamesInt.java: In addition to
implementing all the methods in the interface, it has:
-
a constructor that takes two String objects and store them as the two names;
-
a main method for testing all the methods.
-
TwoNamesValue.java for extending TwoNames.java and implementing TwoNamesValueInt.java.
The class implements all the methods defined in TwoNamesValueInt.java
and not defined in TwoNamesInt.java. In addition, it has:
-
a main method for testing the methods defined in this class;
be sure to test the matches both for a String object as input
and for a double value as input.
We split this project into two labs.
-
In the first lab, you write the code
for TwoNames.java that implments TwoNamesInt.java.
-
In the second lab, you write the other interface
and the class that implments it.