Question

In: Computer Science

Write a code snippet to pre-sell a limited number of movie tickets. Each   buyer can buy...

Write a code snippet to pre-sell a limited number of movie tickets. Each

  buyer can buy as many as 6 tickets. No more than 20 tickets can be sold.

  Prompt the user for the desired number of tickets and then display the

  number of remaining tickets. Repeat until all tickets have been sold,

  and then display the total number of buyers.

**********IN JAVA**********

Solutions

Expert Solution

Java code

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {

int totalticketsleft=20;
int temptickettobuy=0;
Scanner sc=new Scanner(System.in);
while(totalticketsleft!=0)
{
System.out.println("How many tickets?");
temptickettobuy=sc.nextInt();

if(temptickettobuy>6)
{
System.out.println("Ticket count must be less than or equal to 6.");
}
else
if(temptickettobuy<=totalticketsleft)
{
totalticketsleft -=temptickettobuy;
System.out.println("Tickets remaining: "+totalticketsleft);
}
else
{
System.out.println("Tickets left: "+totalticketsleft);
System.out.println("Try again");
}

}


   }
}

Sample output

How many tickets?                                                  

7                                                                  

Ticket count must be less than or equal to 6.                      

How many tickets?                                                  

10                                                                 

Ticket count must be less than or equal to 6.                      

How many tickets?                                                  

5                                                                  

Tickets remaining: 15                                              

How many tickets?                                                  

6                                                                  

Tickets remaining: 9                                               

How many tickets?                                                  

4                                                                  

Tickets remaining: 5                                               

How many tickets?                                                  

6                                                                  

Tickets left: 5                                                    

Try again                                                          

How many tickets?                                                  

3                                                                  

Tickets remaining: 2                                               

How many tickets?                                                  

3                                                                  

Tickets left: 2                                                    

Try again                                                          

How many tickets?                                                  

2                                                                  

Tickets remaining: 0  


Related Solutions

Write a code snippet for the following:   You need to control the maximum number of people...
Write a code snippet for the following:   You need to control the maximum number of people who can be in a   restaurant at any given time. A group cannot enter the restaurant if they   would make the number of people exceed 100 occupants. Use random numbers   between 1 and 20 to simulate groups arriving to the restaurant. After each   random number, display the size of the group trying to enter and the number   of current occupants. As soon as the...
Write a java code snippet to prompt the user for the number of names they’d like...
Write a java code snippet to prompt the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Task 1. to be completed. 1.1 - Write a small Python snippet code that can revert...
Task 1. to be completed. 1.1 - Write a small Python snippet code that can revert an array of N element (Please do not use the default function “reverse()). 1.2 - There is a famous programming (algorithm) concept that can vastly reduce the complexity of Recursive Fibonacci Algorithm. 2 .a) What is the name of this concept 2.b) Write the execution time and memory complexity of Fibonacci sequences, once this concept is applied 2.c) Explain the main idea behind this...
*****IN JAVA***** A run is a sequence of adjacent repeated values. Write a code snippet that...
*****IN JAVA***** A run is a sequence of adjacent repeated values. Write a code snippet that generates a sequence of 20 random die tosses in an array and that prints the die values, marking the runs by including them in parentheses, like this: 1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 (3 3) Use the following pseudocode: inRun = false for each valid index i in the array If inRun...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then prints the following output: a. every element (on a single line) b. every element at an even index (on a single line) c. every even element (on a single line) d. all elements in reverse order (on a single line) e. only the first and last elements (on a single line)
Listed below is the number of movie tickets sold at the Library Cinema-Complex, in thousands, for...
Listed below is the number of movie tickets sold at the Library Cinema-Complex, in thousands, for the period from 2004 to 2016. Compute a five-year weighted moving average using weights of 0.1, 0.1, 0.2, 0.3, and 0.3, respectively. Describe the trend in yield. (Round your answers to 3 decimal places.) 2004 8.61 2005 8.14 2006 7.67 2007 6.59 2008 7.37 2009 6.88 2010 6.71 2011 6.61 2012 5.58 2013 5.87 2014 5.94 2015 5.49 2016 5.43 The weighted moving averages...
Listed below is the number of movie tickets sold at the Library Cinema-Complex, in thousands, for...
Listed below is the number of movie tickets sold at the Library Cinema-Complex, in thousands, for the period from 2004 to 2016. Compute a five-year weighted moving average using weights of 0.11, 0.17, 0.26, 0.13, and 0.33, respectively. Describe the trend in yield. (Round your answers to 3 decimal places.)   20048.79 20058.36 20067.78 20076.75 20087.4 20096.5 20106.53 20116.58 20125.56 20135.69 20145.77 20155.44 20165.33 The weighted moving averages are: (9 of them)
a. why it’s illegal to sell but NOT to buy tickets at prices above those printed...
a. why it’s illegal to sell but NOT to buy tickets at prices above those printed on the tickets. **use the supply and demand analysis to explain why the equilibrium ticket price in an illegal secondary market tends to be higher than in a legal secondary market.**   b. Post a thoughtful, well-worded response, a minimum of 8 sentences. Explain the two causes of market failures. Given their definitions, and discuss if the market can be affected by both types of...
Write a java code snippet that allows a teacher to track her students’ grades. Use a...
Write a java code snippet that allows a teacher to track her students’ grades. Use a loop to prompt the user for each student’s name and the grade they received. Add these values to two separate parallel ArrayLists. Use a sentinel to stop. Output a table listing each of the student’s names in one column and their associated grades in the second column.
A salesperson must buy a number of products from a supplier each Monday, to sell them...
A salesperson must buy a number of products from a supplier each Monday, to sell them through the week, which ends on Friday. The salesperson wants to maximize profits, but the number of products sold each week is a random variable. However, the analysis of past year’s data shows the distribution of weekly demand shown in the table below. Demand per week Probability 200 15% 250 25% 300 20% 350 35% 400 05% One product cost the salesperson $4.00, which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT