Practice modelling a large real world domain and what you have learned about using:
- classes
- inheritance
- abstract classes
- interfaces
Model a ThemePark (with various Attraction and Stalls) and its Visitors.
Remember to model class diagrams first, then write tests, then write code.
Visitorhas age, height, money- Using a
Attractionabstract class (which has aname), create some subclasses forRollercoaster,Dodgems,Park,Playground - Using a
Stallabstract class (which has aname,ownerNameandparkingSpot), create some classes forIceCreamStall,CandyFlossStall,TobaccoStall
ThemeParkstores allAttractionsandStallsin it.ThemeParkhas a methodvisit(Visitor, Attraction)
Introduce some Interfaces to enable charging, restricting and reviewing attractions and stalls:
-
ITicketedpromisesdouble defaultPrice()anddouble priceFor(Visitor) -
ISecuritypromisesboolean isAllowedTo(Visitor) -
IReviewedpromisesint getRating()andString getName()Have some of the classes implement these interfaces. Below are the rules about what the implementations should be:
-
PlaygroundimplementsISecuritybecause it has a maximum age of 15 -
TobaccoStallimplementsISecuritybecause it has a minimum age of 18 -
RollercosterimplementsISecurityand requires a visitor to be over 145cm tall and over 12 years of age
Note: Starting prices are: £8.40
Rollercoaster, £4.50Dodgems, £2.80IceCreamStall, £4.20CandyFlossStall, £6.60TobaccoStall
RollercoasterimplementITicketedand charges tall people over 200cm double feeDodgemsimplementITicketedand charge half price to children under 12 years old- All
Stalls implementITicketedbut they use a starting price whoever is buying ParkandPlaygroundhave no ticketing gate so do not implementITicketedfor these, but all otherAttractions do.
- All
Attractions andStalls have a class variableint rating - All
Attractions andStalls implementIReviewedand implement a getter forint getRating()andString getName() ThemeParkhas a methodgetAllReviewed()which returns an ArrayList ofIReviewed
ThemeParkhas a methodgetAllAllowedFor(Visitor)which takes aVisitorand returns an ArrayList ofITicketedThemeParkhas a method that can return a string with all reviews, returning a String a little bit like this:Rollercoster: 4, Dodgems: 8, Park: 2, IceCream: 6, TobaccoStall: 1