#How to assign numbers in a boolean array
51 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @stable merlin! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
for (int i = 0; i < 5; i++) {
firstClass[i] = true;
economy[i + 5] = true;
}
the for loop iterates 5 times, and in each iteration, the value of i increments by 1. The value of i is used to store true in the firstClass array at index i and in the economy array at index i + 5.
thanks i will try it
also the directions say i have to make it false, so i will do that
how would I print that out
the numbers
right now i have
for(int x=0;x<=4;x++){
System.out.println(firstClass[x]);
}
to print it out
but it just prints out
false
false
false
well. didn't you just make them false
yes
god why is it in comic sans
first off; you shouldn't have 2 arrays
you should just have one, of size 10
ok
for (int x = 0; x <= 4; x++) {
if (firstClass[x]) {
System.out.println(x + 1);
}
}
can u try that
please don't spoonfeed
i didn't
its fine
not the same code
you literally did. that's what spoonfeeding is
(it really isn't.)
not matter
so from this; as the prompt states, seats 1-5 are for first class, 6-10 are economy
you can represent all that as a single array
ok i did that
do you have your input/output system setup
yes
ok
import java.text.*;
public class Program4{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String bookAnother="y";
int seat, choice;
boolean[] firstClass = new boolean[11];
boolean[] economy = new boolean[11];
//int firstClass[]={1,2,3,4,5};
//int economy[]={6,7,8,9,10};
System.out.println("Welcome to the Airline Reservation System\n");
do{
System.out.print("Please enter 1 for First Class or enter 2 for Economy: ");
seat=sc.nextInt();
if(seat==1){
System.out.print("The list of available seats in First Class are:\n");
for(int x=0;x<=4;x++){
//firstClass[x] = false;
System.out.println(firstClass[x]);
}
System.out.print("Choose an available seat: ");
choice=sc.nextInt();
if((choice!=1)||(choice!=2)||(choice!=3)||(choice!=4)||(choice!=5)){
System.out.println("That seat is not available");
}
if((choice==1)||(choice==2)||(choice==3)||(choice==4)||(choice==5)){
System.out.println("You chose seat "+choice);
}
}
if(seat==2){
System.out.print("The list of available seats in Economy are:\n");
for(int y=0;y<=4;y++){
//economy[y]=false;
System.out.println(economy[y]);
}
System.out.print("Choose an available seat: ");
choice=sc.nextInt();
if((choice!=6)||(choice!=7)||(choice!=8)||(choice!=9)||(choice!=10)){
System.out.println("That seat is not available");
}
System.out.println("You chose seat "+choice);
}
System.out.print("\nWould you like to buy another seat(y/n)? ");
bookAnother=sc.next();
if(bookAnother.equalsIgnoreCase("y")){
continue;
}
if(bookAnother.equalsIgnoreCase("n")){
System.out.print("\nThank you for using the Airline Reservation System.");
break;
}
}
}while(bookAnother!="n");
}
}
/*
*/
man im just startin out
yeah ik
hello
oh please don't
what should i dont
the boolean array can be used to check if a certain seat x is reserved by using array[x]