Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application to pre-sell a limited number of cinema tickets. Each buyer

ID: 3777181 • Letter: W

Question

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 pro- gram called TicketSeller 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.

Your requests for tickets will always be positive integers.

You'll need to create a method called public static int processOrder(int order, int numberTickets). The method determines if the order size is less than 4 and less than or equal to numberTickets.

We are going to do this exercise by writing the object that solves the problem first (in a source file called TicketSeller.java) and then testing it using code we write into TicketSeller.java.

Testing Your Code

Your test code, in main for this project will be in TicketSeller.java and will implement a simple user interface. Here is a sample run:

Input the number of tickets you want to sell: 8

Input requested tickets: 1

Thank you for your purchase. There are 7 tickets remaining.

Input requested tickets: 2

Thank you for your purchase. There are 5 tickets remaining.

Input requested tickets: 6

Too many tickets requested, please try again.

Input requested tickets: 9

Too many tickets requested, please try again.

Input requested tickets: 3

Thank you for your purchase. There are 2 tickets remaining.

Input requested tickets: 2

Thank you for your purchase. There are no tickets remaining.

You have had 4 buyers.

Notice that only the valid ticket purchases make someone count as a buyer. Don't worry about other inputs; you'll always get positive integers.

Explanation / Answer

please check the code

import java.util.Scanner;

public class TicketSeller {
public static int count=0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
  
int order; //number of ticket ordered
int numberTickets; //total number of available tickets

System.out.println("Input the number of tickets you want to sell: ");
numberTickets = scanner.nextInt();

//continue until there are no tickets remaining
while (numberTickets>0)
{
System.out.println(" Input requested tickets: ");
order = scanner.nextInt();
if (order<=numberTickets) //check if the ordered number is less than(or equal to) the available tickets
{
numberTickets= processOrder(order,numberTickets);
count++; //increase the count of number of buyers
}
else System.out.println("Too many tickets requested, please try again.");
}
System.out.println("You have had "+count+ " buyers.");
}
public static int processOrder(int order, int numberTickets){
Scanner scanner = new Scanner(System.in);

if(order>4) //check if order is more than 4
{
System.out.println("Too many tickets requested, please try again.");
System.out.println(" Input requested tickets: "); //ask to input number of tickets again
order = scanner.nextInt();
numberTickets= processOrder(order,numberTickets);
count++; //increase the count of number of buyers
  
}
else
{
numberTickets=numberTickets-order; //subtract the number of ordered tickets from available tickets
System.out.println("Thank you for your purchase. There are "+numberTickets+ " tickets remaining. ");
}
  
return numberTickets;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote