Write an application to pre-sell a limited number of cinema tickets. Each buyer can buy as many as 4 tickets. No more than 100 tickets can be sold. Implement a program called Ticket Seller that prompts the user for the desired number of tickets and then displays the number of remaining tickets. Repeat until all tickets have been sold, and then display the total number of buyers.

Question
Asked Oct 12, 2019

Write an application to pre-sell a limited number of cinema tickets. Each buyer can buy as many as 4 tickets. No more than 100 tickets can be sold. Implement a program called Ticket Seller that prompts the user for the desired number of tickets and then displays the number of remaining tickets. Repeat until all tickets have been sold, and then display the total number of buyers.

check_circleExpert Solution
Step 1

Create a java program to pre-sell the cinema ticket.

The name of the program is TicketSeller.

The maximum ticket to sell is 100.

The maximum ticket allowed to sell one buyer is 4.

Prompt user to enter the desired number of tickets.

Display the total number of buyers.

Step 2

/*program to sell ticket*/

//import scanner clas for taking input from user

import java.util.Scanner;

//class name is Ticket Seller

public class TicketSeller {

//main method

public static void main(String[] args) {

//create a object sc of Scanner class

Scanner sc = new Scanner(System.in);

//declaring variable

int totalTicket=100, ticket, buyers=0;

//displaying total ticket

System.out.println("Total Tickets are: "+totalTicket);

//condition for taking input from user until all ticket were sold

while(totalTicket!=0){

//taking input from user

System.out.print("please enter number of ticket you want to buy: ");

ticket=sc.nextInt();

//condition to check that ticket enter by user is less than 4 or not

if(ticket<=4) {

    //condition to check whether enough ticket left or not

    if(ticket<=totalTicket) {

        //subtracting sell ticket from the total ticket

        totalTicket=totalTicket-ticket;

        //counting buyers

        buyers=buyers+1;

        //displaying remaining ticket

        System.out.println("total number of remaining Ticket is: "+totalTicket);

    }

    else

    //when ticket remain less than user want to buy

    System.out.println("Not enough tickets left! Remaining tickets are: "+totalTicket);

  }

else

//when user enter more than 4 ticket

System.out.println("Maximum Tickets allowed to sell one buyer is 4. please enter valid number of tickets");

}

//displaying total number of buyer

System.out.println("Total number of buyers is: "+buyers);

}

}

Step 3

Output:...

Total Tickets are: 100
please enter number of ticket you want to buy: 4
total number of remaining Ticket is: 96
please enter number of ticket you want to buy: 3
total number of remaining Ticket is: 93
please enter number of ticket you want to buy: 4
total number of remaining Ticket is: 89
please enter number of ticket you want to buy: 2
total number of remaining Ticket is: 87
please enter number of ticket you want to buy: 6
Maximum Tickets allowed to sell one buyer is 4.
please enter valid number of tickets
please enter number of ticket you want to buy: 4
total number of remaining Ticket is: 83
please enter number of ticket you want to buy: 3
total number of remaining Ticket is: 80
please enter number of ticket you want to buy: 1
total number of remaining Ticket is: 79
please enter number of ticket you want to buy: 4
total number of remaining Ticket is: 75
please enter number of ticket you want to buy: 3
total number of remaining Ticket is: 72
please enter number of ticket you want to buy: 1
total number of remaining Ticket is: 71
please enter number of ticket you want to buy: 2
total number of remaining Ticket is: 69
please enter number of ticket you want to buy: 4
total number of remaining Ticket is: 65
please enter number of ticket you want to buy: 3
total number of remaining Ticket is: 62
help_outline

Image Transcriptionclose

Total Tickets are: 100 please enter number of ticket you want to buy: 4 total number of remaining Ticket is: 96 please enter number of ticket you want to buy: 3 total number of remaining Ticket is: 93 please enter number of ticket you want to buy: 4 total number of remaining Ticket is: 89 please enter number of ticket you want to buy: 2 total number of remaining Ticket is: 87 please enter number of ticket you want to buy: 6 Maximum Tickets allowed to sell one buyer is 4. please enter valid number of tickets please enter number of ticket you want to buy: 4 total number of remaining Ticket is: 83 please enter number of ticket you want to buy: 3 total number of remaining Ticket is: 80 please enter number of ticket you want to buy: 1 total number of remaining Ticket is: 79 please enter number of ticket you want to buy: 4 total number of remaining Ticket is: 75 please enter number of ticket you want to buy: 3 total number of remaining Ticket is: 72 please enter number of ticket you want to buy: 1 total number of remaining Ticket is: 71 please enter number of ticket you want to buy: 2 total number of remaining Ticket is: 69 please enter number of ticket you want to buy: 4 total number of remaining Ticket is: 65 please enter number of ticket you want to buy: 3 total number of remaining Ticket is: 62

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: In python  Write a for loop (using the range() function) that will print the integers 10,15,20,25,30...

A: Program Instruction:Use range() function to start with 10 and end with 51 as range() function loops ...

question_answer

Q: Using Java Eclipse do the following program: Design a class named Rectangle to represent a rectangle...

A: Program Instructions:Declare variables width and height.Create a default and parameterized construct...

question_answer

Q: What makes a mobile app unique?

A: The factors that makes a Mobile app unique:It is important to determine how a particular app project...

question_answer

Q: What is the mantissa and exponent values if 6.75 is represented in 8 bit binary floating point repre...

A: Answer:Conversion of decimal to 8-bit floating point representation:Step1: convert the integer part ...

question_answer

Q: Write a program that computes the monthly net pay of the employee for a steel factory. The input for...

A: Employee’s gross salary is calculated by following formula , datatype and variables:Variables:rop= r...

question_answer

Q: I have a bit of code that is intended to read a file ("students.txt") and calculate the average, hig...

A: As you are not able to read the file students.txt, here is the source code with little modification ...

question_answer

Q: Write an application starting with ProjectTemplate. Name the class AgeCalcApp. The app needs to prom...

A: To write an application name ProjectTemplate with the class name AgeCalcApp. This application prompt...

question_answer

Q: Replace any alphabetic character with '_' in 2-character string passCode. Ex: If passCode is "9a", o...

A: program to replace first 2-character by ‘_’ from the passcode.isapha() function is used for finding ...

question_answer

Q: Please explain how you solve the follwing problem:

A: a) Set of nullable variables is {A, B, C} as A and C will be null for productions A -&gt; λ and C-&g...