-2

I am getting an error with seatRow = scan.next() and seatLetter = scan.next() how could you convert them. and the if(airplaneSeats == 'X') it says it is an uncompatable operand type

 public static void main(String[]args)
    {
        String airplaneSeatsString = ("1 A B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D");
        String requested = " ";
        char[] airplaneSeats = airplaneSeatsString.toCharArray();
        Scanner scan = new Scanner(System.in);
        boolean seatsRemain = true;
        char seatRow = 0;
        char seatLetter = ' ';

        while (seatsRemain)
        {
            if(seatsRemain == true)
            {
                System.out.print("Input seat row/letter: ");
                seatRow = scan.next;
                seatLetter = scan.next;
                for(int i = 0; i < airplaneSeats.length; i++) {
                    if (airplaneSeats[i] == seatRow)
                        for (int j = 0; j < 4; j++) {
                            if (airplaneSeats[i+j] == 'X')
                            {
                                System.out.println(airplaneSeats);
                            }
                                //print seat taken
                            if (airplaneSeats[i+j] == seatLetter) {
                                airplaneSeats[i+j] = 'X';
                            }
                            if(airplaneSeats == 'X')
                            {
                                seatsRemain = false;
                            }

                        }
                }
        }
        if(seatsRemain == false){break;}
            {
                System.out.print("\nEnter your Seat: ");
                String seat = scan.next();
                requested += seat;
            }
            System.out.println("The Plane is full");
        }

    }
}
A Sdi
  • 657
  • 2
  • 9
  • 23
Olivia
  • 7
  • 6
  • Possible duplicate of [Take a char input from the Scanner](http://stackoverflow.com/questions/13942701/take-a-char-input-from-the-scanner) – shmosel Dec 06 '16 at 00:26
  • "_I am getting an error_" Mind telling us what the error is? – takendarkk Dec 06 '16 at 00:27
  • `airplaneSeats` is an array containing multiple chars. What do you mean by `if(airplaneSeats == 'X')`? – shmosel Dec 06 '16 at 00:27
  • @takendarkk Exception in thread "main" java.lang.Error: Unresolved compilation problems: Type mismatch: cannot convert from String to char Type mismatch: cannot convert from String to char Incompatible operand types char[] and char at Seating.main(Seating.java:19) – Olivia Dec 06 '16 at 00:27
  • Your question says `seatRow = scan.next()` but your code says `seatRow = scan.next;` (with no parens - no method call) – Stephen P Dec 06 '16 at 00:32
  • @shmosel I am trying to see if the whole array is all X's to change seatsRemain = false – Olivia Dec 06 '16 at 00:33

1 Answers1

1

You are comparing the whole array airplaneSeats with 'X' rather you need to compare with a single character of the array like if(airplaneSeats[i] == 'X').

Also, there is a syntax error scan.next while reading the character from Scanner, which needs to be fixed. You need to read the character next().charAt(0) from Scanner as shown below:

seatRow = scan.next().charAt(0);
seatLetter = scan.next().charAt(0);
developer
  • 19,553
  • 8
  • 40
  • 57