Question:
What is the JAVA Code for this sample output?
SheilaMarie
2013-01-08 01:20:58 UTC
Hello everyone, I really need your help guys. I am a beginner student of JAVA Programming. My Instructor gave me this Sample output and to create this program :

Objectives:
• To learn how to use looping structures.
• To learn how to format numbers.

Problem B: Ticket Window

Your favorite New York City Play Company has requested a demand sensitive ticket window program. Because every show is sold out well before the play starts, the Board of Directors believed that to increase the revenue, a demand-based ticket window should be used. This means that since there are a limited number of tickets available for each show, the current ticket price at the moment is calculated by the following equation.

CurrentTicketPrice = (MaximumTicketPrice/TicketsAvailable)

There should also be an option to set the minimum ticket price so that the price can be regulated. Your program will run until all the tickets are sold. You must check to make sure that no one asks for more tickets than are available at any point in time. The Board of Directors would also like to know the Total Income for the night once all the tickets have been sold.

Sample Output 1:

Welcome to Rent’s Ticket Window.
How many tickets are available? 5
What is the Maximum Ticket Price? P500
What is the Minimum Ticket Price? P20
--------------------------------------
Tickets are currently: P100.00
We only have 5 ticket(s) available.
How many tickets would you like to buy? 1
1 Ticket(s) will be P100.00
Enjoy the show!
--------------------------------------
Tickets are currently: P125.00
We only have 4 ticket(s) available.
How many tickets would you like to buy? 2
2 Ticket(s) will be P250.00
Enjoy the show!
--------------------------------------
Tickets are currently: P250.00
We only have 2 ticket(s) available.
How many tickets would you like to buy? 2
2 Ticket(s) will be P500.00
Enjoy the show!
--------------------------------------
We are now Sold Out!
Tonight we brought in P850.00

Sample Output 2:

Welcome to Rent’s Ticket Window.
How many tickets are available? 50
What is the Maximum Ticket Price? P2500
What is the Minimum Ticket Price? P500
--------------------------------------
Tickets are currently: P500.00
We only have 50 ticket(s) available.
How many tickets would you like to buy? 4
4 Ticket(s) will be P2000.00
Enjoy the show!
--------------------------------------
Tickets are currently: P500.00
We only have 46 ticket(s) available.
How many tickets would you like to buy? 40
40 Ticket(s) will be P20,000.00
Enjoy the show!
--------------------------------------
Tickets are currently: P500.00
We only have 6 ticket(s) available.
How many tickets would you like to buy? -9
Please enter a number between 0 and 6.
--------------------------------------
Tickets are currently: P500.00
We only have 6 ticket(s) available.
How many tickets would you like to buy? 10
Please enter a number between 0 and 6.
--------------------------------------
Tickets are currently: P500.00
We only have 6 ticket(s) available.
How many tickets would you like to buy? 3
3 Ticket(s) will be P1,500.00
Enjoy the show!
--------------------------------------
Tickets are currently: P833.33
We only have 3 ticket(s) available.
How many tickets would you like to buy? 3
3 Ticket(s) will be P2,500.00
Enjoy the show!
--------------------------------------
We are now Sold Out!
Tonight we brought in P26,000.00

>> I really need your help guys.. Thanks in Advance :-)
Five answers:
Jhon
2013-01-08 22:00:35 UTC
Hi Sheila,

How are you? I hope this code can help you...



import java.io.*;

import java.text.*;



public class TicketWindow {



public static void main(String [] args) throws IOException

{

BufferedReader console = new BufferedReader(new InputStreamReader (System.in));

DecimalFormat df = new DecimalFormat("P #,##0.00");





int TicketsAvailable;

double MaximumTicketPrice;

double MinimumTicketPrice;

int AmountTicketBuy;

double CurrentTicketPrice;

double AmountDue;

double total=0;







System.out.println("Welcome to Rent's Ticket Window");

System.out.print("How many tickets are available? ");

TicketsAvailable = Integer.parseInt(console.readLine());

System.out.print("What is the Maximum Ticket Price? P");

MaximumTicketPrice = Integer.parseInt(console.readLine());

System.out.print("What is the Minimum Ticket Price? P");

MinimumTicketPrice = Integer.parseInt(console.readLine());





while (TicketsAvailable > 0) {



CurrentTicketPrice = MaximumTicketPrice / TicketsAvailable;



if (CurrentTicketPrice < MinimumTicketPrice)

CurrentTicketPrice = MinimumTicketPrice;



System.out.println("--------------------------------------");

System.out.println("Tickets are currently: " + df.format(CurrentTicketPrice));

System.out.println("We only have "+TicketsAvailable+" ticket(s) available;");

System.out.print("How many tickets would you like to buy? ");

AmountTicketBuy = Integer.parseInt(console.readLine());





if (AmountTicketBuy <=0 || AmountTicketBuy > TicketsAvailable)



System.out.println("Please enter a number between 1 and "+ TicketsAvailable +".");



else {

TicketsAvailable = TicketsAvailable - AmountTicketBuy;



AmountDue = AmountTicketBuy * CurrentTicketPrice;

System.out.println(AmountTicketBuy+" Ticket(s) will be " + df.format(AmountDue));

System.out.println("Enjoy the show!");



total = total + AmountDue;

}

}

System.out.println("--------------------------------------");

System.out.println("We are now Sold Out!");

System.out.println("Tonight we brought in " + df.format(total));

System.out.println("");



System.out.println("\n**** THANK YOU ****\n\n");







}

}



i hope this code can help you..

Enjoy :-)

also you can ask me anytime if there are any errors.. this is my skype :arjhonc91
AnalProgrammer
2013-01-08 09:32:58 UTC
Objectives:

• To learn how to use looping structures.

• To learn how to format numbers.



You won't learn those objectives if you don't make an attempt at this.



Have fun.
Rocky
2013-01-08 10:23:26 UTC
Is it a Java Desktop Application (Swing) or just u need the code ?
brilliant_moves
2013-01-08 11:15:46 UTC
Have a go at writing the code yourself. Then, if you get stuck, post your code and we'll be able to help. We're not here to do it all for you.
?
2013-01-08 14:04:07 UTC
To learn looping structures, you can read:


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...