I need to figure out how to set my overall ticket limit (aticket + cticket) to 100 and if a customer goes over the limit, then they are told that they have ordered too many tickets and that they need to try again and then it loops back through until they order less than a total of 100 tickets. Can someone please help?

import java.util.Scanner;			// Needed for the Scanner class
import java.text.NumberFormat;		// Needed for number format class

public class Movie 
	
	{
		// Create a Scanner object to read input.
		static Scanner keyboard = new Scanner (System.in);
		
		public static void main(String[ ] args)
		
		{
			boolean cinema = true;			// Needed to apply master loop.
			boolean validInput;				// Needed to apply primary loop.
			boolean fullday;				// Needed to apply primary loop.
			boolean check = true;			// Needed to apply primary loop
			boolean overall = true;
			boolean positive = true;		// Needed to apply secondary loop.
			boolean list = true;			// Needed to apply secondary loop.
			boolean decision = true;		// Needed to apply secondyloop.
			boolean yesno = true;			// Needed to apply secondary loop.
			
			
			double adult = 8.25;			// Stores the adult ticket price.
			double day = 0.0;				// Stores the day time ticket price.
			double children1 = 0.0;			// Stores the children ticket prices.
			double children2 = 0.0;			// Stores the children ticket prices.
			double total1 = 0.0;			// Stores the total cost.
			double total2 = 0.0;			// Stores the total cost.
			double total = 0.0;				// Stores the overall total cost.
			int atickets = 0;				// Stores the number of adult tickets.
			int ctickets = 0;				// Stores the number of child tickets.
			int enter = 0;					// To hold the movie choice.
			int capacity = 0;				// The total theater capacity.
			String answer = null;			// To hold an answer to the first Yes or No question.
			String answer2 = null;			// To hold an answer to the Day or Evening question.
			String time = null;				// To hold an answer to the Day or Evening question.
			String sol = null;				// To hold an answer to the second Yes or No question.
			
			NumberFormat nf = NumberFormat.getNumberInstance( );	// Defines the number format.
			nf.setMinimumFractionDigits(2);		// Sets the minimum decimal places.
			nf.setMaximumFractionDigits(2);		// Sets the maximum decimal places.
			
			System.out.println("\nWelcome to the Movie Theater");
			
			
			// Calculate the price of a day ticket.
			day = adult * 0.80;
			
			// Calculate the price of a child's ticket based on the evening price.
			children1 = adult * 0.70;
			
			// Calculate the price of a child's ticket based on the day price.
			children2 = day * 0.70;
			
			while(cinema)
			{
				while(list)
				{
					System.out.println("\nHere are the movies showing presently: ");
					
					System.out.println(" ");
					
					System.out.println("           Title" + "					   Daytime Price" + "	Child Daytime Price"+ "		Evening Price" + "		Child Evening Price");
					System.out.println("-----------------------------------------------------------------------------------------------------------------------------------------------------------");
					System.out.println("1. Burn After Reading						" + nf.format(day) + "		       " + nf.format(children2) + "			     " + nf.format(adult) + "			" + nf.format(children1));
					System.out.println("2. Journey to the Center of the Earth 3D			" + nf.format(day) + "		       " + nf.format(children2) + "			     " + nf.format(adult) + "			" + nf.format(children1));
					System.out.println("3. Tropic Thunder						" + nf.format(day) + "		       " + nf.format(children2) + "			     " + nf.format(adult) + "			" + nf.format(children1));
					System.out.println("4. Lakeview Terrace						" + nf.format(day) + "		       " + nf.format(children2) + "			     " + nf.format(adult) + "			" + nf.format(children1));
					
					System.out.println(" ");
					
					System.out.print("\nPlease choose a movie number: ");
					
					do
					{
						enter = keyboard.nextInt( );			// Stores the chosen movie.
						validInput = true;
						if ( (enter < 1) || (enter > 4))		// Defines the invalid boundaries (but true by definition).
						{
							System.out.print ("\n(You must pick a movie 1 through 4): ");
							validInput = false;										 
						}				
					}while(!validInput);			
					
					
					System.out.print("\nYou chose movie number " + enter + ". Is this correct? (Y or N)?: ");
					
					do
					{
						answer = keyboard.next ();
						yesno = true;
						if (!answer.equalsIgnoreCase("Y") && !answer.equalsIgnoreCase("N"))	// Defines the invalid boundaries (but true by definition).
						{
							System.out.print ("\n(You must pick Y or N): ");
							yesno = false;
						}
					}while (!yesno);
					
					do
					{
						if (answer.equalsIgnoreCase("N"));			// Ignores case sensitivity.
						else if (answer.equalsIgnoreCase("Y"))		// Ignores case sensitivity.
							list = false;							// If Yes is recorded, then we may proceed. If no is recorded, then we begin the loop over again.
						else
							yesno = false;
						
					}while (!yesno);
					
				}
				
				while(decision)
				{
					System.out.print("\nIs this a day or an evening show?: (Please answer with D for day or E for evening): ");
					
					do												// Makes sure the movie choice is valid.
					{
						
						time = keyboard.next( );					// Stores the chosen movie.
						fullday = true;
						if  (!time.equalsIgnoreCase("D") && !time.equalsIgnoreCase("E"))	// Defines the invalid boundaries (but true by definition).
						{
							System.out.print ("\n(You must type in D or E): ");
							fullday = false;										 
						}
					}while (!fullday);
					
					System.out.print("\nYou chose " + time + ". Is this correct? (Y or N)?: ");
					
					
					do												// Asks the user if he/she is sure of the choice. If yes, then the program continues on. If not, the program loops back to the beginning menu.
					{
						
						answer2 = keyboard.next ();					// Stores the answer to the question above.
						fullday = true;								// If Yes is recorded, then we may proceed. If no is recorded, then we begin the loop over again.
						if (!answer2.equalsIgnoreCase("Y") && !answer2.equalsIgnoreCase("N"))	
						{
							System.out.print ("\n(You must pick Y or N): ");
							fullday = false;
							
						}
					}while (!fullday);
					
					do
					{
						
						if (answer2.equalsIgnoreCase("N"));			// Ignores case sensitivity.
						else if (answer2.equalsIgnoreCase("Y"))		// Ignores case sensitivity.
							decision = false;						// If Yes is recorded, then we may proceed. If no is recorded, then we begin the loop over again.
						else
							fullday = false;
					}while(!fullday);	
					
				}			
				
			
				do
				{
					System.out.print("\nHow many adult tickets? ");
					atickets = keyboard.nextInt( );			// Stores the chosen number of tickets.
					System.out.print("How many children's tickets? ");
					ctickets = keyboard.nextInt( );
					positive = true;
					if ( (atickets < 0) || (ctickets < 0))		// Defines the invalid boundaries (but true by definition).
					{
						System.out.println("\n(You must pick a positive number): ");
						positive = false;										 
					}				
				}while(!positive);
				
				
				
				
			}
					
			
			// Calculate the final balance based on the day or evening pick.
			if (time.equalsIgnoreCase("D"))
				total1 = atickets * day + ctickets * children2;
			else if (time.equalsIgnoreCase("E"))
				total2 = atickets * adult + ctickets + children1;
			
			
			// Calculate the final balance.
			total = total1 + total2;
			System.out.println("\nYour total is $" + nf.format(total) + ".");
		}		
	}

The following loop itself could be modified to perform this check you need :-

do {
  System.out.print("\nHow many adult tickets? ");
  atickets = keyboard.nextInt( );
  System.out.print("How many children's tickets? ");
  ctickets = keyboard.nextInt( );
  positive = true;
// Defines the invalid  boundaries (but true by definition).
// add the new condition with an "||" in this "if" condition itself
// or use another if block
  if ( (atickets < 0) || (ctickets < 0))	 {
    System.out.println("\n(You must pick a positive number): ");
    positive = false;										 
  }				
}while(!positive);

To the "if" condition just add ((atickets+ctickets) > 100) with an "||" operator, so even when the sum of the two is greater than 100 it will prompt the user the enter them again. You will however need to modify your error message to reflect exactly why the user has to input the "aticket" and "cticket" values again taking into account the new case.

@stephen84s : Yes but in this case, what happens if he inputs the number of adult tickets to be 110 ? You still ask him for the number of child tickets, which since he has already jumped the maximum count is wrong on our part. If he enters the no. of adult tickets to be greater than 100 he should be warned of the limitation there itself rather than proceeding.
Take a look at this post for a solution.

@stephen84s : Yes but in this case, what happens if he inputs the number of adult tickets to be 110 ? You still ask him for the number of child tickets, which since he has already jumped the maximum count is wrong on our part. If he enters the no. of adult tickets to be greater than 100 he should be warned of the limitation there itself rather than proceeding.
Take a look at this post for a solution.

Yeah thats correct, but I assumed the thread starter will figure out what additional checks to put, so I just pointed out where to put his checks.

Thanks ...that helped out a lot!. I figured the rest of it out this morning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.