0
//Created by
//Ticket Reservation System of 5 first class and 5 economy tickets


import java.util.Scanner;

public class Planeticket
{
	public static void main(String args[])
	{
		boolean EconArray[] = new boolean[5]; // boolean array with 5 elements

		boolean FirstArray[] = new boolean[5];

		Scanner input = new Scanner(System.in);
		int value;

			for(int i =0; i < 10; i++)
			{
			System.out.print("Please Enter 1 for First Class or Enter 2 for Economy:");

			value = input.nextInt();

				if( value == (1))
				{
					EconArray[i] = true;
					System.out.println("Your Economy ticket has been booked\n");
				}
				else

				System.out.println("Economy is full would you like to upgrade to first class?");

				if(value == (2))
				{
					FirstArray[i] = true;
					System.out.println("Your First class ticket has been booked\n");
					break;
				}

			}

	}
}

Please dont go shredding my code to nothing. I understand there is a lot of work to be done. Right now i wish to understand why if i hit either 1 or 2 5 times i get an error. I should be able to hit 1 4 times filling the first class array leaving one empty seat and then hit 2 a couple times to fill some of those seats. As it stands after the 5 entry no matter a 1 or a 2 it calls a error. Please dont throw indepth code at me cause i wont know what it means. just why after i enter a 6th selection does it throw an error message.
Thanks in advance alonewolf23.

2
Contributors
2
Replies
7
Views
6 Years
Discussion Span
Last Post by alonewolf23
0

You have 2 arrays to fill up, but you only have one variable i to keep track of both - so if you have 4x econ they go into EconArray[0-3] then if there's a 1st it goes into FirstArray[4] not FirstArray[0]. You need two variables corresponding to the 2 arrays to keep track of how many places you have filled in each.

0

Thank you, that helped alot as for the future suggestions I will have to get with my prof. for a more interactive learning session.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.