Java error- Help needed!?

Java error- Help needed!?
Im working on a program and am getting the following error message of: “can not find symbol variable i”.

Here is my code:

import java.util.Scanner;

class jets24
{
public static void main (String[]args)
{
Scanner input= new Scanner (System.in);

//variables//

int TotalLuxurySeats = 4 ;
int TotalExecutiveSeats = 6 ;
int Option = 0 ;
int LuxurySeatsSold=0;
int ExectutiveSeatsSold=0;
String[] CustomerName= new String [10];

// seat objectives within the array//

for(int i=0; i<10; i++)
{
if (i<4)
CustomerName[i]=new String ("Luxury");
else
CustomerName[i]=new String ("Exectutive");
}
while(Option!=4 || LuxurySeatsSold>0 || ExectutiveSeatsSold>0)
{
System.out.println(” Hello and welcome to CCNJet! “);

System.out.println(” “);

System.out.println(” Please select an option from the following menu “);
System.out.println(” “);
System.out.println(” 1. Book a luxury seat “);
System.out.println(” 2. Book an exectutive seat “);
System.out.println(” 3. Display seat details/availability “);
System.out.println(” 4. Exit “);
Option=input.nextInt();

if ((Option==1) && (LuxurySeatsSold<4))
{
System.out.println(" Please enter your name ");
CustomerName[LuxurySeatsSold]=input.next();
System.out.println(" ");
System.out.println(" Thank you for your luxury seat order " + CustomerName[LuxurySeatsSold] + " You have seat number " + (LuxurySeatsSold + 1));
LuxurySeatsSold++;
LuxurySeatsSold=TotalLuxurySeats -1;
}
if ((Option==2) && ExectutiveSeatsSold<4)
{
System.out.println(" Please enter your name ");
CustomerName[ExectutiveSeatsSold]=input.next();
System.out.println(" ");
System.out.println(" Thank you for your exectutive seat order " + CustomerName[ExectutiveSeatsSold] + " You have seat number " + (ExectutiveSeatsSold+ 1));
ExectutiveSeatsSold++;
ExectutiveSeatsSold=TotalExecutiveSeats -1;
}
if (Option==3)
{
System.out.println(" Here is a report of available/unavailable seats on the aircraft ");
System.out.println("");

System.out.println(" Luxury seats ");
while (CustomerName[i]!=null) // can not find symobol variable i//
for (int i=0;j<4;i++)
{
if(customerName[i]==null) break;
System.out.println("Seat Number: " + i + "Name: " + customerName[i]);

}
System.out.println("Executive Seats");
while(CustomerName[k]!=null)
for( k=4;l<10;k++)
{
if(customerName[k]==null) break;

System.out.println("Seat Number : " + k + "Name: " + customerName[i]); }

}
}
if (Option==4)
{
System.out.println("=============");
System.out.println(" Good bye,thanks for looking!");
System.out.println("=========");

}
}
}

Can anyone see the problem?

Thanks,

Ben

Best answer:

There is a problem with this section:
while(CustomerName[k]!=null)
for( k=4;l<10;k++) <--- what is 'l', k might increase infinitely and make outofbound error
{if(customerName[k]==null) break;
System.out.println("Seat Number : " + k + "Name: " + customerName[i]); } <-- here is your error, 'i' is out of scope
}

Tags: , , ,

Under Forum

1 Comment for Java error- Help needed!?

  • 1. colanth  |  February 29th, 2008 at 1:49 am

    I’m not going to go through the entire code without even knowing WHERE the error is occurring, but is your use of i within the scope of your definition of i? Using a variable outside its defined scope is using an undefined variable.

Leave a Comment for Java error- Help needed!?

Required

Required, hidden

Trackback this post  |  Subscribe to the comments via RSS Feed


Forum