Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

You are going to implement three different pricing models for an airline, and calculate the revenue generated by each strategy (model) for computing the total revenue of the airline's flights. The Strategy pattern is a good example of Subtyping. In other words, we are programming to an interface, not Subclassing, in which case we would be using an abstract class. So create a generic Strategy interface, called Model. It will have one method, long getRevenue(List flights) which takes a List of flights as its only parameter and returns a long of whole dollars. Then create 3 different concrete strategies, SinglePrice, TwoClasses, and MultiClass. These will all implement the Model interface. The Model interface should define a constant for the base ticket price ($300), and the fixed cost to fly a plane ($50,000). For now, we'll ignore distance and different plane sizes. The three models will behave as follows: SinglePrice will just take the number of passengers, multiply by the constant ticket price to get a total revenue for a flight, then subtract the fixed cost. It will then total all the flights and return the revenue total. TwoClasses will take the number of passengers, and price 1/3 of them as Business Class, where the cost is 1.5 times the ticket price. 2/3 will be in Coach at 0.75 times the ticket price. The fixed cost will be 1.1 times higher (for the business class meals and lost seats). MultiClass will take the number of passengers, and price 1/10 of them as First Class, where the cost is 4 times the ticket price. 1/5 will be in Business class at 1.5 times the ticket price. The rest (7/10) will be in Coach at 0.75 times the base ticket price. The fixed cost will be 1.2 times higher (for the first and business class meals and lost seats).