Question
Description: In this assignment, we will learn about Object-Oriented Programming by creating an application that uses Java classes to simulate multiple people and the multiple
Description:
In this assignment, we will learn about Object-Oriented Programming by creating an application that uses Java classes to simulate multiple people and the multiple bouncy houses that they may enter -- as long as they don't push the total weight of people in that bouncy house over its limits.
Requirements:
- You should follow all proper coding conventions and practices as discussed in class
- You should not use global variables or static methods (other than your main method) anywhere in this assignment.
Step 1:
- Create a new Java class named PartnerLab1. Add your main method to this class.
- Create a new Java class named "BouncyHouse"
- Create a new Java class named Person
Each of these classes should be created in its own (appropriately named) file. These three files should be uploaded to Canvas.
Step 2:
Implement a properly encapsulated "BouncyHouse" class that has the following attributes:
- Weight limit
- Total current weight of all occupants in the bouncy house
(Note: all weights in this assignment can be represented as whole numbers)
and methods to perform the following tasks:
- Set the weight limit
- Set the total current weight
- Return all info about the bouncy house (you may want to call this method getInfo())
- Add a person to the bouncy house by:
- Testing if their weight would cause the bouncy house to exceed its weight limit if they entered.
- Returning true and updating the total current weight of the bouncy house to reflect the addition of their weight (if they are able to enter).
- Returning false if they are unable to enter.
Step 3:
- Create a no argument constructor for the BouncyHouse class that sets both the weight limit and the total weight to a default value of 0.
Step 4:
Implement a properly encapsulated "Person" class that has the following attributes:
- Name
- Weight in pounds
and methods to perform the following tasks:
- Get the name
- Get the weight
- Return all info about the person (you may want to call this method getInfo())
Step 5:
- Create a two argument constructor for the Person class that takes in the name and weight and sets both attributes accordingly
Step 6: <-- spoiler alert: this is the hard part...
- Modify your class structure such that:
- Your design supports the creation of multiple bounce houses
- You can store and access the names of each person in each bounce house.
- Note that there are a few valid ways to accomplish this. Discuss the upsides and downsides of each approach with your partner. Hints will be given in class.
Step 7:
In your main method:
- Create two instances of your Bouncy House class. Use your setter to set the weight limit of each bouncy house. There is no need to modify the total weight at this point since nobody is in the bouncy house to start.
- Repeatedly prompt the user to add a person (including name and weight), or type "q" when done with that bounce house.
- Attempt to add each person to the bouncy house.
- If the attempt is successful, display "Person added" along with the name and weight of that person.
- If the attempt is unsuccessful, display "Person could not be added."
- Note that people will initially be added to the first bounce house until the user types 'q', which will cause subsequent people to be added to the second bounce house. Typing 'q' a second time will indicate that the user is done adding people to the second bounce house.
- Finally, display all of the info for both bouncy houses and each of the people inside it. Each field should be labelled.
BONUS (for up to 5 extra points)
- Create an addPeople method in Bouncy House that takes in an array of Person objects as a parameter
- Add logic in the addPeople method to determine which people should enter the bouncy house to allow the maximum number of people without going over the weight limit
- Return an array of people who can enter based on the previous step
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started