Você está na página 1de 11

Java Programming Problem

1 Introductionssqw
The following programming problem is designed to help us assess programming ability,
including:

Java skills

Object oriented design skills

Test-driven development skills

Please read the problem carefully and then solve it using standard Java programming
techniques. When you are happy with your solution, please email back to your
representative.

Some guidelines to follow are:

Please do not spend more than one working day on the exercise. If you
havent solved it in this time, send us what you have.

Send us your complete solution, including the source code, any unit
tests, Ant builds etc. We need to be able to run your solution, verify that
it works and also have a good look at your code.

Our firewall will not allow batch files in an email attachment, even within
a zip file. Please change the extension of any batch files to .txt, and let
us know which files you have changed.

You are free to implement any mechanism for feeding input into your
solution (for example, using hard coded data within a unit test). You
should provide sufficient evidence that your solution is complete by, as a
minimum, indicating that it works correctly against the supplied test
data.

You may not use any enhanced functionality of the language or any
external libraries to solve this problem; however, you may use external
libraries or tools for building or testing purposes. For example, if you
were solving a date difference problem you would not be allowed to use
Java Programming Problem

a pre-programmed function to calculate the date difference, but you


would be allowed to use JUnit or Ant to assist your development.

The programming problem is supposed to be fun. Enjoy it!


Java Programming Problem

2 The Holiday Planner


Java Programming Problem

2.1 The Problem

The Cheapo Holiday Company would like to provide its customers with information about
the price of travel included in its holiday packages. In particular, it would like to show its
customers the cheapest travel itinerary for their selected holiday.

The model of a travel itinerary is necessarily simplified. For this problem an itinerary for a
group of passengers consists of the following three distinct legs:

1. A transfer to airport leg: A single journey by car, at a cost of 30p / mile,


or by train, at a cost of 15p / passenger / mile. If a car is used for the
transfer then an additional parking fee of 10, levied by the airport, must
be taken into consideration. It is assumed that all passengers and their
luggage will fit into a single car and therefore the cost of car travel is the
same, independent of the number of passengers.

2. A flight itinerary leg: One or more flights, at a cost of 10p / passenger /


mile. Flights are selected from a flight schedule which contains a pre-
defined set of aircraft routes. Each route defines the airports the aircraft
stops at. A passenger may board or depart a single aircraft at any airport
along the route. Routes are one-way and independent of each other; a
passenger cannot change to another route or plane halfway through a
flight itinerary.

3. A transfer to destination leg: A single journey by coach at a cost of 50p /


passenger / mile.

Your task is to write a program that will quote the cheapest price possible for a given travel
itinerary by finding the cheapest transfer and flight prices.
Java Programming Problem
Java Programming Problem

2.2
Java Programming Problem

2.3 Input

Input consists of:

1. A flight schedule, consisting of a number of flight routes (e.g. AB500


BC400 CD800), where each member of the route represents a departure
airport (as a single character), a destination airport (as a single
character) and a distance. Followed by:

2. One or more travel itineraries (e.g. 2, A110, D20), consisting of:

The number of passengers.

The nearest airport and the transfer distance to that airport.

The destination airport and the transfer distance from that airport
to the destination.
Java Programming Problem

2.4 Output

For each itinerary, the program should determine the following:

The number of the itinerary (numbered consecutively, starting with


Itinerary #1).

Either

No Such Route if the requested itinerary can not be quoted for (i.e.
there is no flight route between the requested airports)

Or

The cheapest transport type (Train, Car, Plane or Coach) and cost (in s
and pence) for each leg of the itinerary and the cheapest total cost of
the journey. If a leg has no cost associated with it (e.g. the passengers
lives less than a mile from their nearest airport or the destination is less
than a mile from the destination airport) then the information for that
leg should not be displayed.
Java Programming Problem

2.5
Java Programming Problem

2.6 Sample Input


AB500 BC400 CD100 DE600

DE800 EB600 BF400

FD100 DC800 CE200 EB300

2, A110, D20

4, A110, D20

2, D20, A110

1, A45, C5

4, D100, B0

1, A50, F20
Java Programming Problem

2.7 Sample Output

Itinerary #1:
Train: 33.00 Plane: 200.00 Coach: 20.00 Total: 253.00

Itinerary #2:
Car: 43.00 Plane: 400.00 Coach: 40.00 Total: 483.00

Itinerary #3:
No Such Route

Itinerary #4:
Train: 6.75 Plane: 90.00 Coach: 2.50 Total: 99.25

Itinerary #5:
Car: 40.00 Plane: 520.00 Total: 560.00

Itinerary #6:
No Such Route

Você também pode gostar