Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A . Basic Inheritance: Write a class named TrainTicket that can be used to represent a train ticket for a trip. Every train ticket has

A. Basic Inheritance:
Write a class named TrainTicket that can be used to represent a train ticket for
a trip. Every train ticket has the name of the passenger, the number of
checked bags, and the trip distance, and we must be able to retrieve each of
these pieces of information for any ticket. (Note: train tickets are non-
transferrable and the trip cannot be changed - this means the name of the
passenger and the trip distance can never change once the ticket is created.)
We must also be able to compute the cost of the train when told the per km
rate for the ticket using the method: computeCost(double rate). The cost of
the ticket must also include the cost of checked bags which is $45 per bag.
For example, if the passenger has 3 checked bags, the trip distance is 1050km
and the per km rate is $1.50, the computeCost method will return 1635.
Next, create a subclass of TrainTicket named BusinessTicket. This class will be
used to represent a train ticket that is in the business train carriages which have
larger seats and more space. The cost of a business ticket has an additional
charge of $104.50 added to the base cost of a train ticket. The business train
cars have both regular seats and reclining seats. Customers may choose to
have a reclining seat for an additional $55.75 charge.
Finally, create a third class named SleeperCarTicket. This class will also be a
subclass of TrainTicket. Sleeper car tickets are for carriages that contain
sleepers - these are seats can be converted into beds. Sleeper car tickets
must also keep track of the number of nights the passenger wants to reserve
the sleeper for. There is an additional charge of $167 added to the base cost
for a sleeper car ticket. In addition to this, there is a per night fee. The first
night is $95, and each additional night is $80.
Be sure to write javadoc comments for all three classes. Include a comment
for the class, for each instance variable and constant, and for each method.
Use @author, @param & @return tags where appropriate.
B. Test Driver
Write a test driver named TicketApp that exercises many of the methods from
the TrainTicket, Businessticket and SleeperTicket classes. Use the following test
values:
Grace purchased her ticket during peak season at a per km rate of $1.35km.
Joy purchased her ticket using her frequent rider card and received a reduced
rate of $0.75km.
Tim purchased his ticket during the off season at a per km rate of $1.15km.
Margaret purchased her ticket during peak season also, her rate was $1.20km.
Barbara purchased her ticket during the off season at a per km rate of
$0.95km.
Shafi and Alan both purchased their tickets during a sale at a per km rate of
$0.85km.
Lynn and Jeanette both purchased their tickets during a special promotion at
a per km rate of $0.65km.
Your program will produce output in a table, formatted as shown here (this table
does not contain all the information - it is only a sample):
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago