java- can not find string?
java- can not find string?
Whilst working on a program I have camer across the program, of can not find String, this was whilst initalizing my array values.
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)
String[i]= CustomerName("Luxury");//can not find symbol variable string//
else
String[i]=CustomerName ("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)//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 what i am currently doing wrong?
Thanks,
ben
Cheers mate.
Best answer:
String[i]= CustomerName(“Luxury”);//can not find symbol variable string//
This is wrong….it should be CustomerName[i] = new String(“Luxury”)
u can’t use a class name as a variable….
more explanation
————————
String[] CustomerName ….etc
declares an array of strings….
it’s like a collection of 10 names…
and each name is a string…so CustomerName[i] is name of ith customer..and so on :D
Under Forum

1 Comment for java- can not find string?
1. Micky | October 16th, 2007 at 9:34 am
You didn’t ask this, but I answered another question of yours and caught 2 things.
1) while(Option!=4 || LuxurySeatsSold>0 || ExectutiveSeatsSold>0)
Shouldn’t that be an and && otherwise it can be slipped through.
You are sasying if anything of these things are true enter the while.
Shouldn’t they ALL be true?
2)This statement
ExectutiveSeatsSold++;
ExectutiveSeatsSold=TotalExecutiveSeats -1;
Why are you doing this?
First you advance the seat count then you reassign its value.
But you never use the Total
You can compare the seat count to the totalEx seats, but dont change the seat count, you will override where you are putting people.
Take a look to see what I mean
Leave a Comment for java- can not find string?
Trackback this post | Subscribe to the comments via RSS Feed