Question
JAVA Write an application that models an evening stroll on a street containing several buildings, some of which are haunted. Make sure your application compiles
JAVA
Write an application that models an evening stroll on a street containing several buildings, some of which are haunted. Make sure your application compiles and runs correctly.
The buildings on the street should be modelled using an abstract Building class, which is extended by concrete House and Asylum subclasses. Each building has a double variable for its size and a boolean variable indicating whether or not it is haunted. In addition, each House (but not each Asylum) has some specific feature which is described by a String variable (for example, "charming fireplace" or "updated kitchen".) An Asylum (but not a House) also has a String variable for its name (e.g., "State Home For The Criminally Insane.")
House and Asylum need constructors. You need getters and setters for the other variables; think about which ones should be in Building and which ones should be in the concrete classes.
Each building has an explore() method, but they are different in House and Asylum. House's explore() prints out the size of the house and information about its special feature. Asylum's explore() prints the name of the Asylum and its size. Each explore() method also warns the user if the building is haunted by printing a message like "Watch out! A ghost!"
The street is modelled by a Street class which has a name, a constructor, a list of Buildings, a way to add a Building to the list, a getter for the street name, and a getNumHaunted() method, which returns an int indicating how many of the Buildings in the list are haunted.
Street must also have a stroll() method. Stroll() prints a message like "Let's go for a stroll on Maple Street," using Street's getter to get the actual name of the street, then then iterates through the list of Buildings, calling each Building's explore() method. It then uses getNumHaunted() to show how many of the Buildings are haunted.
Finally, use a driver class to instantiate a Street, add five houses and one asylum to it, and then call Street's stroll() method. Here is sample output:
Let's go for a stroll on Maple street!
You pass a 165.4 sq. meter house with a(n) updated kitchen
Watch out! A ghost!
You pass a 208.75 sq. meter house with a(n) charming fireplace
You pass a 171.5 sq. meter house with a(n) capacious septic tank
You pass a 35000.25 sq. meter asylum called The California Home For People Who Like Cats
Watch out! A ghost!
You pass a 211.4 sq. meter house with a(n) beautiful lawn
You pass a 301.0 sq. meter house with a(n) bonus room
Watch out! A ghost!
3 of the buildings on Maple street are haunted.
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