Source: This assignment is adapted from UIUC’s CS242.
Due: March 17, Tuesday, 23:55.
Language: Java
Submission: Your project must be called CSAir. Your main file must be called CSAir.java.
Context: You are a senior software engineer for a new international airline, CSAir. For CSAir to start selling tickets, some software needs to be written to manage the extensive route map. Being the senior software engineer of CSair, it’s of course your task to write this wonderful program. The initial requirements for this new software are:
CSAir’s flight information has been provided to you as a JSON file here. In Java you’ll need to use a JSON API to parse the contents of the file.
Read the JSON data and convert it to in-memory City and Flight objects that point to each other. That is, you will have City objects that keep information such as the code, population, region, etc. of the city as well as the flights departing from that city. Similarly, you will have Flight objects that keep the distance and the source/destination cities.
Note that if there is a flight from city A to B, having a direct reference from city A to city B is not sufficient, because you have to keep the distance information for a flight.
Also note that in the JSON data, there is only one flight listed between a pair of cities. This stands for two flights (one from city A to B, the other from B to A).
In this part, you have to write your own City and Flight classes.
Provide a console-based interaction for the user to run queries on your data. Your interface should allow the user to:
All of this information should be calculated at query time from your objects and not be hard-coded into your source. Your program should be console-driven, that is it should start up, prompt the user for input, and be able to perform any combination of valid operations without exiting. Also, be careful to check for invalid input. For instance, what happens when a user queries data about a city that CSAir does not fly to? The JSON data should be parsed once at the beginning of the program. After you construct your objects, do NOT use the JSON data to calculate the answer to a user query; all those calculations must be done through the objects.
Watch this video.
Watch this video.
Penalty: Up to 10 points for bad format.
Due: March 31, Tuesday, 23:55.
Complete Part I if you have any missing features. Refactor your code to come up with a clean design. Make sure that you have an object graph, where your City objects have pointers to Flight objects, and Flight objects have pointers to City objects.
Extend your menu to allow the user to
Extend your menu to allow the user to
TBD
Due: April 7th, Tuesday, 23:55.
Goal: Practice Test-Driven-Development by writing unit tests.
Read Wikipedia article on Test-Driven Development.
Read Clean Code Chapter 9: Unit Tests, Chapter 15: JUnit.
Check the Resources page for the TDD exercise we did in the class.
An itinerary is a list of connected flights. E.g. BOG-LIM-MEX-LAX is an itinerary that includes the flights BOG-LIM, LIM-MEX, MEX-LAX (in this order). Each flight in an itinerary is called a leg.
Copy the following Itinerary
class to your project.
public class Itinerary {
public Itinerary(Flight firstLeg) {
// TODO Write test cases first
}
public void appendCity(City city) {
// TODO Write test cases first
}
public double cost() {
// TODO Write test cases first
return 0;
}
public double duration() {
// TODO Write test cases first
return 0;
}
public int distance() {
// TODO Write test cases first
return 0;
}
}
You can add fields and auxiliary methods into this class as you see fit. Do NOT change the signature of the given methods.
To expand an existing itinerary with a new leg, use the
appendCity
method. This method should raise an
IllegalArgumentException
if there does not exist a direct flight from the last city
of the itinerary to the new city.
For instance, if we have an itinerary that is currently
IST-MIL-ESS,
it should not be possible to
append LAX to this itinerary because there is no
direct flight from ESS to LAX.
cost
, distance
and duration
methods
are supposed to return values according to the following
definitions:
The total distance of an itinerary is the sum of the distances of its legs.
An itinerary has a cost. To calculate cost, we have the following algorithm: the first leg of any flight costs $0.35 per kilometer traveled. Each additional leg costs $0.05 less per kilometer. If the cost for a leg of the itinerary becomes free, keep the cost free for the rest of the itinerary.
CSAir operates a fleet of jets that all have a cruising speed of 750 kph. Each jet spends the first 200 kilometers of its flight uniformly accelerating from 0 kph to 750 kph, stays at 750 kph while it is cruising, and then decelerates uniformly from 750 kph to 0 kph during the last 200 kilometers of its flight. If a flight is less than 400 kilometers in distance, the jet accelerates uniformly for the first half of the flight and decelerates uniformly for the second half of the flight. In addition, passengers experience some layover time while waiting at airports for connecting flights. The schedule to determine the layover time works as follows. The airport with the least number of outbound flights (i.e. 1) has a layover time of 2 hours. For airports with 2 outbound flights, the layover time is 1hr 50min. Continue subtracting 10 minutes for each additional outbound flight that CSAir has from an airport to calculate its layover time.
Write JUnit test cases for the Itinerary
class.
You should write test cases before you implement the Itinerary class.
Once you write test cases, commit your file to SVN.
Then start implementing the Itinerary
class.
Finally commit again.
Here is a video to help you get started.
Extend the console-based menu of your program to read an itinerary from the user as a comma-separated list of city codes. Then print the distance, cost, and duration information.
If an itinerary cannot be formed according to the user input,
output an appropriate warning message.
E.g. If the user enters IST,MIL,LON
,
print “There is no flight from MIL to LON.
”
If the user enters IST,ZZZ,LON
,
print “ZZZ is not a valid city code.
”
A web-based CSAir application is available at http://srl.ozyegin.edu.tr/cgi-bin/csair.py
You can check the distance/cost/duration values for itineraries on this web page.
Note that I’m NOT asking you to develop a webpage; I just want a console program from you. However I’m providing you with this web page so that you can play around.