You are on page 1of 6

JAVA PROGRAMMING I

TITLE

 AirLine Operation System

DESCRIPTION

In this assignment you are and write a set of Java classes that simulate the
operation of an airline. An airline operates over a number of different
routes and uses a number of different aircraft types on each route. In this
assignment we will restrict the number of routes per airline to 10, and the
number of aircraft per route to 10. You are required to create three Java
classes, Airline, Route and Aircraft. A class called Assign1, which is the
driver class, has been supplied with this assignment.

Each of these three classes will have a constructor method which has a
signature identical to that used for that class in the Assign1 class. Each
will also have a toString() method that will return a String that can be
used to display information about the object.

Class data members should be private with appropriate setter and getter
methods for those that need to be accessed.

You must also produce UML class diagrams showing class relationships
and Object diagrams for the airline, its Hong Kong route and the aircraft
it uses on this route. These diagrams must be produced in a software
format that can be read by Microsoft Word. (No other format will be
accepted.)

Aircraft
An aircraft class has the following data members.

Data members
String type a design of the aircraft type eg. Boeing 747
int passengers the number of passengers that aircraft can carry
int crew the number of crew members needed
double maintCost the cost of maintenance per hour of flying
double fuelEffic the tonnes of fuel used per hour of flight

Page 1 of 5
Methods

1. A constructor method that accepts values for, and initialises all the
data members of an Aircraft object.
eg. Aircraft A330 = new Aircraft ("Airbus A330",
220,14,600,4.0);
Aircraft(type,passegers,crew,maintcosts/h,fueleff
ic);

2. toString() method that returns the Aircraft type and passenger


capacity.

3. calcRunningCosts() a method that calculates the total cost of


one hour of
flight. This is made up from the cost of fuel used, the cost of the aircrew
and the
maintenance costs as well as an overheads cost.

To calculate these we assume all aircrew are paid $100 per hour in flight
and the cost of jet fuel is $767 per tonne. To this we add the hourly
maintenance costs and an overhead figure of $8000 to cover the costs
associated with buying a plane and the costs of administration and
infrastructure required on the ground.

Route

We assume all routes start in Adelaide. The Route class has the following
data members.

Data members
String destination eg “Hong Kong”
double flyTime the hours taken to reach the destination.
(Most jets fly at similar speeds so the time is the same for a given route)
int passengerVol passengers flying on this route each day
double fare We assume all passengers pay the same fare.
Aircraft [] planes An array of aircraft objects that have been
assigned to that route.

Methods

Page 2 of 6
1. A constructor that accepts values for and initialises destination, flyTime
and
passengerVol for the route.

2. toString() method that return a String that is formatted as shown


Adelaide – Hong Kong, 9.5 hours, 350 passengers
A330 Airbus, 220
Boeing 737, 150

3. void setFare(double fare) a setter method that sets the


value of the fare.

4. double breakEven() a method that calculates the total costs of


flying planes on that route. (Total of the hourly running cost per plane *
the flyTime )

5. double income() returns the income generated from passengers


paying the fare on that route.

6. void addAircraft(Aircraft a) inserts the Aircraft object


into the next available place in the Aircraft array for that route.

Airline

The Airline class contains an airline name and a collection of Routes

Data members
String name
Route [] routes An array of Routes

Methods

1. A constructor that accepts and initializes the name variable.

2. String toString(). Returns a String that shows the airline


name and a list of the Route objects it flies, formatted as follows.

Dingo Air
Adelaide - Hong Kong, 9.5 hours, 300
passengers

Page 3 of 6
Airbus A330, 220
Boeing 737, 150

Adelaide - Singapore, 7.5 hours, 500 passengers


Boeing 747, 350
Boeing 737, 150
Adelaide - Auckland, 4.0 hours, 400 passengers
Airbus A330, 220
Airbus A330, 220
Adelaide - Perth, 3.5 hours, 270 passengers
Boeing 737, 150
Boeing 737, 150

3. void addRoute(Route r) Accepts a Route object as a


parameter and
places it in the next available position in the Route array.

4. double calcDailyProfit() inspects each route flown,


calculates the income from each route and subtracts the break-even costs
for that route to return a daily profit value.

Each of the classes above must include appropriate comments including

Assign1

This class is provided for you below. It is the driver class for this
assignment as it is the only class that has a main method. In it, several
Aircraft objects, Route objects and an Airline object are created. Methods
are used to assign aircraft to Routes and Routes to an Airline. Methods of
the airline are used to display the Airline and calculate its daily profit.
Your code should include appropriate comments. Both code and diagrams
should include your name and email ID as well as the statement

Assign1.java
import java.text.*;
public class Assign1
{
public static void main (String [] args)
{
Assign1 a1 = new Assign1();
a1.runAirline();
}
public void runAirline()
{
NumberFormat cf= NumberFormat.getCurrencyInstance();

Page 4 of 6
//--- Create Aircraft objects --------
Aircraft A330 = new Aircraft ("Airbus A330",
220,14,600,4.0);
Aircraft B747 = new Aircraft ("Boeing 747",
350,20,1000,7.0);
Aircraft B737 = new Aircraft ("Boeing 737",
150,7,450,2.5);
Aircraft BAe464 = new Aircraft ("BAe 464", 60,4,300,1.3);

//--- Create Routes -----------

Route HNK = new Route("Hong Kong", 9.5, 300);


Route SNG = new Route("Singapore", 7.5, 500);
Route AUC = new Route("Auckland", 4.0, 400);
Route PER = new Route("Perth", 3.5, 270);
Route MTG = new Route("Mt Gambier", 0.75, 45);

//--- Assign sufficient aircraft to routes to cover


passenger
//volume

HNK.addAircraft(A330);
HNK.addAircraft(B737);
SNG.addAircraft(B747);
SNG.addAircraft(B737);
AUC.addAircraft(A330);
AUC.addAircraft(A330);
PER.addAircraft(B737);
PER.addAircraft(B737);
MTG.addAircraft(BAe464);

//--- Assign fares to routes and display route costs ---


System.out.println("\nRoute Costs");
HNK.setFare(1100);
System.out.println("HNK : "+cf.format(HNK.breakEven()));
SNG.setFare(800);
System.out.println("SNG : "+cf.format(SNG.breakEven()));
AUC.setFare(450);
System.out.println("AUC : "+cf.format(AUC.breakEven()));
PER.setFare(450);
System.out.println("PER : "+cf.format(PER.breakEven()));
MTG.setFare(130);
System.out.println("MTG : "+cf.format(MTG.breakEven()));

//--- Create Airline object ---


Airline a1 = new Airline("Dingo Air");

//--- Assign Routes to Airline ---


a1.addRoute(HNK);
a1.addRoute(SNG);
a1.addRoute(AUC);
a1.addRoute(PER);
a1.addRoute(MTG);

//--- Display the Airline object ---


System.out.println("\n"+a1);

//--- Display the daily profit ---


System.out.print("\nDaily profit: ");
System.out.println(cf.format(a1.calcDailyProfit()));

Page 5 of 6
}
}

Output of Assign1.java
Route Costs
HNK : $229,287.25
SNG : $205,773.75
AUC : $104,544.00
PER : $77,472.50
MTG : $7,272.83

Dingo Air
Adelaide - Hong Kong, 9.5 hours, 300 passengers
Airbus A330, 220
Boeing 737, 150
Adelaide - Singapore, 7.5 hours, 500 passengers
Boeing 747, 350
Boeing 737, 150
Adelaide - Auckland, 4.0 hours, 400 passengers
Airbus A330, 220
Airbus A330, 220
Adelaide - Perth, 3.5 hours, 270 passengers
Boeing 737, 150
Boeing 737, 150
Adelaide - Mt Gambier, 0.75 hours, 45 passengers
BAe 464, 60

Daily profit: $412,999.68

You have to prepare pseudocode or flowchart before start writing the code.
(using Microsoft word or other drawing programs).

Page 6 of 6

You might also like