Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class airplane{
- public static void main (String[] args){
- String []seats= new String[5];
- int []age= new int[5];
- int passAge;
- String passenger;
- int seatNo;
- for (int a=0; a<seats.length; a++) {
- seats[a] = "x";
- age [a]=0;
- System.out.println(seats[a]);
- System.out.println(age[a]);
- }
- for (int i=0; i<seats.length; i++) {
- Scanner userInput = new Scanner(System.in);
- System.out.print("Enter a seat number: ");
- seatNo=userInput.nextInt();
- while (seats[seatNo-1]!="x"){
- System.out.print("Seat taken choose again");
- System.out.print("Enter a seat number: ");
- seatNo=userInput.nextInt();
- }
- System.out.print("Enter a passenger name: ");
- passenger=userInput.next();
- seats[i] = passenger;
- System.out.print("Enter a passenger age: ");
- passAge=userInput.nextInt();
- age[i] = passAge;
- }
- System.out.print("All seats are booked up!");
- for (int b=0; b<seats.length; b++) {
- System.out.println("Seat "+(b+1)+" "+seats[b]+" "+age[b]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment