Practice modelling a large real world domain and what you have learned about using:
- classes
- inheritance
- abstract classes
- interfaces
Look through the start code and understand what is set up for you already.
Visitor
class with age, height and money.Attraction
abstract class with name, rating and visitCount (which starts at 0).Rollercoaster
,Dodgems
,Park
andPlayground
classes which inherit fromAttraction
Stall
abstract class which has name, owner name, rating and parking spot.CandyFlossStall
.TobaccoStall
andIceCreamStall
which inherit fromStall
.
All of these classes have tests set up for them.
Introduce some Interfaces to enable charging, restricting and reviewing attractions and stalls:
-
ITicketed
promisesdouble defaultPrice()
anddouble priceFor(Visitor)
-
ISecurity
promisesboolean isAllowedTo(Visitor)
-
IReviewed
promisesint getRating()
andString getName()
Have some of the classes implement these interfaces. Below are the rules about what the implementations should be:
-
Playground
implementsISecurity
because it has a maximum age of 15 -
TobaccoStall
implementsISecurity
because it has a minimum age of 18 -
Rollercoster
implementsISecurity
and requires a visitor to be over 145cm tall and over 12 years of age -
All Stalls and Attractions implement
IReviewed
.
- £8.40 for
Rollercoaster
- £4.50 for
Dodgems
Rollercoaster
implementsITicketed
and charges tall people over 200cm double feeDodgems
implementsITicketed
and charge half price to children under 12 years old
Create a ThemePark
class to manage the attractions and stalls.
ThemePark
stores allAttractions
andStalls
in it.ThemePark
has a methodgetAllReviewed()
which returns an ArrayList ofIReviewed
objects.- Add an empty
visitedAttractions
ArrayList toVisitor
which stores a list ofAttractions
and a method to add an attraction to the list. ThemePark
has a methodvisit(Visitor, Attraction)
calls for the attraction to increment itsvisitCount
by 1 and adds the attraction to the visitorsvisitedAttractions
list.
ThemePark
has a method that can return a new HashMap<String, Integer> with all reviews. The HashMap will have a key of the name and value of review.ThemePark
has a methodgetAllAllowedFor(Visitor)
which takes aVisitor
and returns an ArrayList ofIReviewed
that the visitor is allowed to go on.