Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Writing java program to calculate fare cost

807598May 23 2006 — edited May 24 2006
Write a program called FareCost to allow a user to find out the price they have to pay for a fare for a train.

The price of a ticket depends on three factors:

? User. There are two kinds of users: Adult (more expensive) and child (cheaper).
? Kind of seat. There are three kinds of seats for the train: ?economy? (the least expensive), ?business?, and ?sleeper? (the most expensive).
? Type of ticket holder. There are two types of ticket holders: concession (with 30% deduction) and non-concession.

The program prompts the user for user type, kind of seat, and type of ticket holder ? in that order ? and then displays the price for the ticket. The program must allow the user to cancel the operation at any stage.

The prompts must be exactly as shown in the following sample run (the user inputs are shown in italic):

We will need information on the type of user, the type of seat, and the type of ticket holder.

Options for type of users are:
1. Adult
2. Child
x. Cancel
Please enter your choice (1, 2, or x): 3

It is an invalid choice for users. Please try again.

Options for type of users are:
1. Adult
2. Child
x. Cancel
Please enter your choice (1, 2, or x): 1

Options for type of seat:
1. Economy
2. Business class
3. Sleeper
x. Cancel
Please enter your choice (1, 2, 3, or x): 3

Options for type of ticket holder:
1. Concession
2. Non-concession
x. Cancel
Please enter your choice (1, 2, or x): 1

The price for the ticket is: $70.00
Thank you for using the program.

Also, whenever the user chooses to terminate the operation (i.e., with option ?x?), the program must show the message ?Thank you for using the program.? before terminating itself.

The prices for non-concession tickets are shown in the following tables.

------------------Economy-------------Business------------Sleeper------------
======================================================
Child....................$30..........................$60.........................$100...................
Adult.....................$60..........................$80.........................$140..................

Concession tickets enjoy a 30% deduction, the price is to be rounded down to the nearest dollar value if necessary.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2006
Added on May 23 2006
21 comments
4,366 views