Question: Train Tickets Machine: Write a JAVA program to sell train tickets. There are three type of tickets A,B,C to New jersey, New York. The prices

Train Tickets Machine:

Write a JAVA program to sell train tickets.

There are three type of tickets A,B,C to New jersey, New York.

The prices are as follow:

New Jersey : $15.00 (C), $17.75(B), $20.90 (A)

New York : $17.50 (C), $19.75(B), $22.50 (A)

There are 10 tickets of each type (Total=60 tickets)

The program will ask the user which tickets he want to buy, then ask him to put money,

The program will accept: $100,$50,$20,$10,$5,$1 dollars bills, and 25,10,5 cents coins.

The program should reject any other amount.

The program will keep asking the user for more money till the money amount put is equal to or more than the price of the ticket, If it is more, the program will return the exceeding amount.

Then the program will continue indefinitely asking users which ticket they want to buy.

If there are no more ticket available of certain type, the program should display this at the beginning.

If no ticket are available in the machine at all, the message displays should be : Machine closed: SOLD OUT.

Example of output (The output of your program should be like this)

Which state you buy ticket to: (1: New jersey, 2: New York): 2

Which ticket class you want to buy (1: A, 2: B, 3:C): B

The price of New York ticket class B is : $19.75

Please put money in the machine:$ 5

You have $5, put more: $17

Rejected, You have $5, put more: $1

You have $6, put more: $.25

You have $6.25, put more: $10

You have $16.25, put more: $5

Thank you.

Please take your ticket.

You change is $1.50, please take them

New York ticket class B are SOLD OUT.

Which state you buy ticket to: (1: New jersey, 2: New York): 2

Which ticket class you want to buy (1: A, 3:C):

Please do this program in Java and the output of the program should be similar to the example that I provided above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!