You are on page 1of 5

Introduction:

In this project, we will solidify our class making abilities. Specifically, we will create multiple
classes, use files to store and retrieve data, write JavaDoc documentation, and test our code
with JUnit tests. To begin, create a project in Eclipse named Project1. Now, create multiple
classes that follow the requirements for each class listed below.

Class Address:
Create a class named Address that has the following private Instance Properties:
● int streetNum - An integer variable that holds the street number of the address.
This value cannot be negative
● String streetName - A String object that holds the street name
● String city - A String object that holds the name of the city
● String state - A String object that holds the two-letter abbreviation of the state
● String zipCode - A String object that holds the five-digit ZIP code

The Address class should contain the following methods:


● public Address() - The default (or empty) constructor that initializes the instance
properties to the default values (all Strings to “” (except for the state which should
default to “OH” and zipCode which should default to “00000”) and the int to 0)
● public Address(int streetNumber, String streetName, String city, String state,
String zipCode) - The workhorse constructor that initializes the instance properties
with the input parameters
● public Address(Address address) - The copy constructor that initializes the
instance properties using the values of another Address’s instance properties
● public boolean equals(Object o) - Override the default Object class equals(). This
method should return true if the Object parameter is an instance of Address and if the
two Addresses have the same street number, street name, city, state, and ZIP code
and false, otherwise
● public String toString() - Override the default Object class toString(). This method
should return a String representation of the Address object that includes the street
number, street name, city, state, and ZIP code. An example return call of this
method would be as follows: “2000 Main Street, Santa Monica, FL, 30309”
● A set of getters and setters for all Instance Properties

Class Bicycle:
Create a class named Bicycle that has the following private Instance Properties:
● int bicycleId - An integer variable that holds the ID of the account. This ID is auto
generated and starts from 500. The very first bicycle object will have an ID of 500. Each
bicycle object after will get an ID incremented by 5. For example, the 2nd and 3rd
bicycle objects are going to have an ID of 505 and 510, respectively.
● String brand - A String object that holds the name of the company that built the bike
● String color - A String object that holds the color of the bike
● double miles - A double value that holds the number of miles the bike has traveled
● BikeOwner owner - A BikeOwner object that holds the information for the owner of
the bike

The Bicycle class should contain the following methods:


● Bicycle() - The default (or empty) constructor that initializes all values to their
default values (All Strings to “” and BikeOwner to null)
● Bicycle(String brand, String color, double miles) - A partial constructor that
initializes instance properties with its input parameters. The BikeOwner should be set to
null. Recall that the id field should be auto generated
● Bicycle(String brand, String color, double miles, BikeOwner owner) - The
workhorse constructor that initializes the instance properties with the input
parameters. Recall that the id field should be auto generated
● Bicycle(Bicycle bike) - The copy constructor that initializes the instance properties
using the values of another Bicycle’s instance properties. Recall that the id field is
auto generated and should not be copied from the bicycle in the parameter
● public boolean equals(Object o) - Override the default Object class equals(). This
method should return true if the Object parameter is an instance of Bicycle and if the
two Bicycles have the same brand and color, and false, otherwise
● public String toString() - Override the default Object class toString(). This method
should return a String representation of the Bicycle object that includes the id, color,
brand, and BikeOwner. An example return call of this method would be as follows: “Bike
505, red Schwinn, 10.5 miles, Owner: Elizabeth Hale”
● A set of getters and setters for all Instance Properties EXCEPT the bicycleId
field. We ONLY want a getter, as the id field is auto generated so we do not want
to be able to set it

Class BikeOwner:
Create a class named BikeOwner that has the following private Instance Properties:
● String name - A String object that holds the name of the bike owner
● Address address - An Address object that holds the address of the bike owner
● Bicycle bike - A Bike object that holds the information about the bike this bike
owner has
● boolean wearsHelmet - A boolean value that returns true if the bike owner wears
a helmet when they ride their bike, and false otherwise

The BikeOwner class should contain the following methods:


● BikeOwner(String name, Address address) - A partial constructor that
initializes instance properties with its input parameters. The Bicycle should be null
and wearsHelmet set equal to false
● BikeOwner(String name, Address address, Bicycle bike, boolean wearsHelment)
- The workhorse constructor that initializes the instance properties with the input
parameters
● public void rideBike(double miles) - This method drives a bike a parameter-
specified number of miles. This method should use the BikeOwner’s bicycle. If the
BikeOwner does not have a bicycle, then this method should throw an
IllegalArgumentException
● public void rideBike(Bicycle diffBike, double miles) - This method drives a bike a
parameter-specified number of miles. This method should use the parameter-
specified bicycle
● public double chancesOfCrashing() - This method should return the chance of the
BikeOwner crashing their bike. It should always return 0.0 if the BikeOwner
wearsHelmet or they don’t have a bike. If wearsHelmet is false, it should return the
amount of their bicycle’s miles divided by 1000 as the chance.
● public String toString() - Override the default Object class toString(). This method
should return a String representation of the BikeOwner object that includes the
name, address, and the bike they own. An example return call of this method would
be as follows (with the line breaks included):
“Name: Elizabeth Hale
Address: 2000 Main Street, Santa Monica, FL, 30309
Bicycle: Bike 505, red Schwinn, 10.5 miles, Owner: Elizabeth Hale”
● A set of getters and setters for all Instance Properties

JUnit Tester Classes:


Create three test classes, one class for each of the custom classes listed above, to write JUnit
tests for:
● Create a class named AddressTester to test the Address class
● Create a class named BicycleTester to test the Bicycle class
● Create a class named BikeOwnerTester to test the BikeOwner class

In each tester class, you have to test all the methods of the classes including constructors,
getters and setters (that include logic in the method), and the remaining public interface
methods. You can create multiple objects of the class for testing purposes. When you test, you
need to make sure you think about all possible scenarios (edge cases) for each individual
method. See the corresponding Lecture Code for examples.

Testing ID Auto Generation:


You must also test the auto generation of the ID for the Bicycle class. Please make sure you use
a static variable to auto generate IDs. When you use a static variable for the Bicycle class, you
need to give it protected level access (no private or public keywords). The declaration should
look like this:
protected static int staticID = 500;

Now, when you are going to write your JUnit tests for the Bicycle class, you will be able to
directly access these static variables. One important thing to remember is that static variables
retain their values between JUnit test cases. So, you must manually reset the static variables for
each test method by doing the following:

Bicycle.staticID = 500;

JavaDoc Style Comments:


You are required to make JavaDoc comments for all classes (including the tester classes) and
methods including parameters and return descriptions.

Important Note:
For validation checking, you must check the following instance parameters:
● Address
○ streetNumber - it cannot be negative
○ state - valid length of two and made up of alphabetical characters
○ zipCode - valid length of 5 (we don’t care about 9 number long zip codes) and
made up of numeric characters
● Bicycle
○ miles - it cannot be negative

If any of the previous instance parameters are invalid, you should throw an
IllegalArgumentException (Hint: In order to manually throw an Exception, you’ll have to use the
throw keyword)

Submission Instructions:
Submit your .java files (Address.java, Bicycle.java, BikeOwner.java, AddressTester.java,
BicycleTester.java, and BikeOwnerTester.java) to the corresponding Project 1 assignment’s
CODE plugin.
Rubric:
Task Grade
Address
Correctly implement constructors 8
Correctly implement getters and setters 6
Correctly implement equals() method 4
Correctly implement toString() method 4
Bicycle
Correctly implement constructors 8
Correctly implement getters and setters 6
Correctly implement equals() method 4
Correctly implement toString() method 4
BikeOwner
Correctly implement constructors 8
Correctly implement getters and setters 6
Correctly implement toString() method 4
Correctly implement both rideBike() methods 6
Correctly implement chancesOfCrashing() method 4
Tester Classes
Test constructors 9
Test getters and setters with validation logic 8
Test equals() and toString() methods 5
Test rideBike() and chancesOfCrashing() methods 6
JavaDoc and Intermediate Submission
Total 100

You might also like