SE450: Homework: Assignment #3 [22/22] Previous pageContents

Read Jia chapter 6.

Skim this article on junit.

And read this tutorial of junit.


Goal - to implement the Strategy pattern.

Update your homework #2 solution (using any parts that you would like) to use the Strategy pattern. Put it in the package se450.studentid.hw3 where studentid is your DePaul ID.

Assume that you have a file of flight records, like last week. It is a text file in which each line contains a single record, and each record consists of the following colon-delimited fields:

Airline Code: Airplane Type: Flight Number : Departing Airport : Arriving Airport: Time: # of passengers

A sample line is as follows:

ASA:B73Q:144:ORD:SFA:13:230

Assume that the time is just a whole hour in 24HH format, as an integer. The passenger count is also an integer. All other records are strings

You are going to implement three different pricing models for an airline, and calculate the revenue generated by each strategy (model) for the total of the airline's flights in the file.

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 interace that is part of the hw3 package, in my case it would be se450.mwright1.hw3.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:

Treat the Main program as the Context. In other words, it will have to switch between the ConcreteStrategies as needed.

Use the Airline and Flight classes from last week. The Main class's main() method should take two command line arguments, the filename and the airline code to be processed and return results for all parts of the program. The program should return the total revenue for the day's flights for the airline code passed in. Proper error handling is expected for conditions like no file found, no flights for an airline, etc. Include a good usage statement if the program is invoked with no arguments.

Grading is as follows:

Continue to ask questions on the discussion list

Submit a zip file that contains all your source code and grader.txt. As always, make sure that your source is in the correct package for your code. The grader will take off points if you have extra or incorrect directories included.

To test your homework, take the zip file, move it to a new directory, unzip it, and then run

javac -classpath . se450\studentid\hw3\Main.java
java -classpath . se450.studentid.hw3.Main

On Unix, you will need to change your \ to /. If this doesn't work, your homework submission isn't correct! (and you will miss the correct submission points on your homework)

You can use the grader.txt file from the previous homework.

Due next Monday(1/27) at 5:30 PM

Previous pageContents