Lab 3 Writing an OO Java Program
All work to be added, committed and pushed to the remote by 11:59PM on Sunday.IMPORTANT: While you are in the lab, login in to a lab desktop, bring up chrome and visit this attendance app This will register your attendance in the lab. Make sure you have, at some point during the lab, logged in directly on a lab system (using the lab keyboard, monitor and mouse, no ssh!!).
Overview
This week, you are going to implement two Java classes (see the javadoc), test them, and play with them. You will complete the classes SodaCan.java and Person.java so that when TestSodaCan.java is executed, you get exactly TestSodaCanOut.txt, when TestPerson.java is executed, you get exactly TestPersonOut.txt. Finally, implement class Scenario.java. All of this is in your repo!!Notes
- Please login and work on the lab systems!!
- Please read all source code before coding.
- Marks for the lab are for committing and pushing your work to the repo and correctly finishing your classes.
- We will be marking Scenario.java, Person.java and SodaCan.java.
- During the lab, if you know what you are doing, and can help your neighbour, then help them. If you need help, ask us or your neighbour.
- You can find the starter code already in your repo.
1. Class SodaCan
Implement the class SodaCan using instance variables and methods to capture the following...- A SodaCan has a type (i.e. Coke, Sprite, Root Beer), it is either open or closed, it has an amount of soda in it (at least 0).
- For this question, assume that SodaCans start out closed with 250cc of soda in them.
- A SodaCan be opened (but can't be closed once opened).
- Once open, either sips (remove 10cc) or gulps (remove 50cc) can be taken from them. Remember, amount must be at least 0 (i.e. if removing 10cc would make amount negative, amount should become 0). Both methods should return the amount of soda actually removed.
- The string representation (from method toString) of a SodaCan displays its type, whether or not it is open/closed, and its amount.
2. Class Person
Implement the class Person using instance variables and methods to capture the following:- A Person has a name and a thirstStatus which is 'satisfied', 'thirsty' or 'very thirsty', and amountDrunk which keeps track of how much soda they have drunk so far.
- A very thirsty person has had less than 175cc of soda. A thirsty person has had less than 375cc of soda. A satisfied Person has had at least 375cc of soda.
- Initially, a Person is very thirsty, since they have had no soda.
- A person can sipFrom(SodaCan), they can also gulpFrom(SodaCan).
- The string representation of a Person displays their name, their thirstStatus and the amountDrunk.
3. Testing your Classes
I have included test classes, which exercises your classes. Please make sure your output exactly matches mine. You may not change the TestXXXXXX.java in any way. Your output should match mine exactly.4. Playing with both classes
- Complete class Scenario.java. Scenario should carry out the steps in its documentation.