CompSci 251: Intermediate Computer Programming Lab 3 – Spring 2020
Introduction
This week’s lab will explore a different design for the homework: one that doesn’t follow principles of encapsulation. Here, we will make the object variables of the Person and Ride classes public, which means the object has no control over what values those variables can take. As a result, when we write a method that uses those variables, we have to test the variables to see if their values are valid.
What you need to do
Import the project into Eclipse.
Look at the Person and Ride classes. They are very simple, and have no methods, only public fields.
Now look at the Park class. Here, your task is to write a single, kind of complicated, method. This method will take a Person and Ride, and check whether the Person can ride the Ride, much like in the homework. This method will have to test the variable fields to ensure they make sense, which is a lot more work for you. Think about why we don’t have to do this much input verification in the homework!
The method should:
1. Receive a Person and a Ride as parameters.
2. If either is null, return false.
3. If the Person has a negative age, height, or number of tickets, return false.
4. If the Ride has a negative value for any of its requirements, return false.
5. If this Park object has a negative value for any of its minimums, return false.
6. Determine the requirements for this Person to ride. For each of age, height, and tickets,
use the Ride object’s requirement, unless it is less than the Park’s minimum; in that case
use the Park’s minimum for that requirement instead.
7. If the Person does not meet any of the three requirements computed in step 6, return
false. A Person does not meet the requirement if their age, height, or number of tickets
is less than the computed requirement.
8. Subtract the computed ticket requirement from the Person’s number of tickets. (THIS IS
THE ONLY STEP THAT SHOULD CHANGE ANY OBJECT’S FIELDS)
9. Return true
Try to finish this method so that you can pass all the tests in TestClass.
To Get Credit
Show your TA that you have made significant progress on the method, can pass many of the tests, and understand what you are working on.
ALSO: explain to your TA why someone might prefer to do things the way the homework is designed instead of this way!