1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
STALIN [3.7K]
2 years ago
8

write an application to presell a limited number of cinema tickets. each buyer can buy as many as 4 tickets. No more than 100 ti

ckets can be sold. Implement a program called TicketSeller that prompts the user for the desired number of tickets and then displays the number of remaining ticket. Repeat until all tickets have been sold, and then display the total number of buyers
Computers and Technology
1 answer:
Rus_ich [418]2 years ago
8 0

Answer:

The program for this question can be given as:

Program:

import java.util.*;  //import package

public class TicketSeller  //define class

{

public static void main(String ar[])  //main method

{

int totalTickets=100,userCount=0,remainingTickets=100,numTickets; // varaibale

try           //try block

{

Scanner ob= new Scanner(System.in);  //input by user

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

while(remainingTickets!=0)          //loop

{

System.out.print("Enter no of Tickets to buy:");      //message.

numTickets=ob.nextInt(); //taking input

if(numTickets<=4)         //conditional statements.

{

if(remainingTickets>=numTickets)

{

remainingTickets=remainingTickets-numTickets;              //calculate remainingTickets

userCount++;

System.out.println("remaining tickets : "+remainingTickets+" user :"+userCount);      

}

else

{

System.out.println("Invalid Input");

}

}

else

{

System.out.println("Invalid Input");

}

}

}

catch(Exception e)            //catch block.

{

}

}

}

Output:

Total tickets:100

Enter no of Tickets to buy: 4

Remaining tickets : 96 User :1

Enter no of Tickets to buy: 4

Remaining tickets : 92 User :2

Enter no of Tickets to buy: 4

Remaining tickets : 88 User :3

.

.

.

Enter no of Tickets to buy: 4

Remaining tickets : 0 User :25

Explanation:

In the above Program firstly we import the package for the user input. Then we declare the class that is (TicketSeller) given in question. In this class we declare the main method in the main method we declare the variable that is totalTickets, userCount, remainingTickets and numTickets .Then we use the exception handling. we use this for providing the validation from the user side that users don't insert value less the 4. In the exception handling, we use the multiple catch block with try block. Then we input from the user and calculate the values and in the last, we print all the values.

You might be interested in
Which step do you think is most useful from big data life cycle.why?
12345 [234]

Explanation:

Business xase evaluation is most useful because (BCA) provides a best-value analysis that considers not only cost but other quantifiable and non-quantifiable factors supporting an investment decision. This can include but is not limited to, performance, producibility, reliability, maintainability, and supportability enhancements.

Mark me brainliest

7 0
1 year ago
What is the oldest malware victor
arsen [322]

Answer:

The oldest malware vector was emails.

Explanation:

Websites were not widespread early on into the internet, however it was very easy to have a virus that uses an email contact list, where it can send itself to other email addresses and spread.

7 0
3 years ago
You are working on a project and need to be able to access the content from home and share the files with other team members. Th
inn [45]
Local server so you can all you use if you guys are near
5 0
3 years ago
Read 2 more answers
How will you keep the buzz going post-hackathon?
Anna71 [15]

Answer:

it would be nice if you gave some form of info here

Explanation:

in other words without information no help aka I'm slow and just need points

8 0
1 year ago
Which font attribute would be most appropriate to make a papers heading stand out?
eimsori [14]

If you want your heading to pop out I would go for bold Becuase it shows the letters darker and bigger which would make the heading the center of attention.

7 0
3 years ago
Read 2 more answers
Other questions:
  • What are the challenges of photographing at night? Why did the photographer “paint” the waterfall with the flashlight?
    9·1 answer
  • Whats a computer scientist.
    5·2 answers
  • Which of the following is true regarding data analysis? a. Disciplines and professions do not provide guidance on data analysis.
    6·2 answers
  • Write a program that uses two input statements to get two words as input. Then, print the words on one line separated by a space
    11·1 answer
  • Viruses which activate themselves after a specific time is called
    10·2 answers
  • You can fit more RAW files on a memory card than JPEG files. true or false
    10·1 answer
  • A network consists of 75 workstations and three servers. The workstations are currently connected to the network with 100 Mbps s
    12·1 answer
  • What is the primary cause of the industrial revolution?
    12·1 answer
  • What stipulates that the source code of any software published under its license must be freely available.
    14·1 answer
  • Network connections implemented with the use of a cable modem take advantage of?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!