| RHS => Allan => Basic Programming => Exercises => TravelAgency |
Updated:
02/02/2004 23:36 WebMaster: allanhn@rhs.dk |
China Travel Agency
The Problem
You are to develop a computer program that can print out bills at the travel
agency ChiTravel. This agency is known for its group-travels to China.
The
program
must be able to read input from the user, calculate and print out the price
pr. person and the total price for a group-travel to China.
The agency has to types of travels with fixed prices:
Normal: 1400 DKK pr. person
Deluxe: 1900 DKK pr. person
The customer will be given a 10% discount on the total price, if the number of travellers is 10 or more.
Question 1 Planning
Before you start programming the solution, discuss in your study group the
following questions:
Input Which data must be read in; i.e. entered by the user?
Constants Which values should be defined as constants (final)?
Variables Which variables (of which type) are needed for the program?
Calculations Which data must be calculated and how?
Output Which data must be printed out and how?
The answers to these questions are to be written down on paper.
This will
give you a pretty good idea on how the program should be structured.
Question 2 Worker class
You are to create a program, which can handle print out of the bills at
ChiTravel.
First, make a worker class ChiTravel.
In this
class you should make the
declarations of variables, constants and constructor(s) you found in question
1.
Create the set- and get- methods you find necesarry.
At first, the only functionality we need, is the calculation of the total price.
Create a method, getPrice, that recieves two parameters:
the
number
of travellers and the type
of travel.
The method should return the total price - remember to take into account that
you get a 10% discount if the number of travellers is 10 or more.
Question 3 Application class
Create an application class, ChiTravelApp,
that contains the usual main method.
Create a variable of the ChiTravel type.
Use
the method getPrice from
this variable to print
out the prices for the following 4 sets of data:
4 travellers - type of travel is Normal
15 travellers - type of travel is Normal
6 travellers - type of travel is Deluxe
20 travellers - type of travel is Deluxe
Question 4 Discount for
old customers
If one of the travellers has used ChiTravel before, the total
price for the group will be reduced as follows:
If 10 or more persons in the group: Discount is 1000 DDK
If 6 - 9 persons in the group: Discount is 500 DDK
Else: Discount is 200 DDK
In ChiTravel add another getPrice method
that recieves three parameters: number of travellers, type of travel and a
boolean value.
If the boolean value
is true it means that one of the travellers has used ChiTravel before.
In that case you should check the number of travellers to see if they get a discount
- using the rule stated above.
If the boolean value is false no traveller has used ChiTravel before
and no discount is given.
Remember that you still get a 10% discount if the number of travellers is 10
or more.
In the main method in ChiTravelApp you should read the following values:
Number of travellers (use showInputDialog from JOptionPane)
Type of travel (use showInputDialog from JOptionPane)
Has one of the travellers used ChiTravel before? (use showXXXDialog from JOptionPane)
When the values are read you should calculate and print out
the total price.
Question 5 Discount for
children
This question is a bit harder - you'll have to plan it carefully.
So discuss
it in your studygroup before you program!!
For children there will be a discount of 5%. But children don't count
in the other discount rules.
Expand the program so it can differentiate between number of adults and
number of children.