找不到标志

时间:2015-04-18 10:51:38

标签: java keyboard

class airlne {
    static String seatsArray[][] = new String[30][6];
    static String columnLetter[] = {"A", "B", "C", "D", "E", "F"};
    static String passName[][] = new String[30][6];
    static String name;
    static int count;
    static double cost;
    static String reservedSeat;

    static int i, j;

    public static void main(String[] args) { //main
        String pickedSeat = new String("");

        System.out.println("\n********************* Welcome To The Fair Airlines **********************");
        System.out.println("*********************                      **********************");
        System.out.println("*********************    Please Book       *********************");
        System.out.println("*********************     Your Seat        **********************");
        System.out.println("*********************                      **********************");
        System.out.println("*********************       \1\2\3\4\5\6         **********************");

        createSeatingArrangment();

        String option = "m";
        while (!option.equals("exit")) {
            printMenu();

            option = Keyboard.readString();

            switch (option) { //switch for menu
                case ("1"):
                    showSeatMap();
                    bookSeat(pickedSeat);
                    break;

                case ("2"):
                    cancelSeat(pickedSeat);
                    break;

                case ("3"):
                    seatsRemaining();
                    break;

                case ("4"):
                    showSeatMap();
                    break;

                case ("5"):
                    ticketCost();
                    break;

                case ("6"):
                    printTicket();
                    break;

                case ("exit"):
                    System.out.println("Thank you. Goodbye");
                    System.exit(0);
                    break;

                default:
                    System.out.println("Invalid option");
                    break;
            }
        }
    }

    static void createSeatingArrangment() {
        for (i = 0; i < 30; i++) {
            for (j = 0; j < 6; j++) {
                seatsArray[i][j] = new String((i + 1) + columnLetter[j]);
            }
        }
    }

    public static void printMenu() { //just prints menu
        System.out.println("Please select an option below:\n"
                + "[1] Book your seat \n"
                + "[2] Cancel your seat \n"
                + "[3] Check how many seats are remaining \n"
                + "[4] See our seats  \n"
                + "[5] Show seat cost\n"
                + "[6] Print Ticket"
                + "\nEnter \'exit\' to exit");
    }

    static void showSeatMap() { // goes through arr and prints
        for (i = 0; i < 30; i++) {
            for (j = 0; j < 6; j++) {
                System.out.print(seatsArray[i][j] + "\t");
            }
            System.out.println("\4");
        }
    }

    static void ticketCost() {
        count = 0;

        for (i = 0; i < 30; i++) {
            for (j = 0; j < 6; j++) {
                if (seatsArray[i][j].equals("X")) {
                    count++;
                }
            }
        }

        double splendidum = 0;
        splendidum = 180 - count;
        cost = 150 + (180 / splendidum);

        System.out.println("     ******* Your ticket will cost " + cost + "   *******     ");
    }

    static void bookSeat(String pickSeatIn) { //booking seat method
        System.out.print("Enter Seat Details: ");
        pickSeatIn = Keyboard.readString();

        if (isSeatAvailable(pickSeatIn)) {
            System.out.println("Enter name");
            passName[i][j] = Keyboard.readString();
            System.out.println("Reservation Confirmed!");
            System.out.println("Dear " + passName[i][j] + " Thanks for booking with us!");
            System.out.println(pickSeatIn + " is now reserved");
            reservedSeat = pickSeatIn;
            System.out.println("");
            ticketCost();
        }
        else {
            System.out.println("This seat is taken!");
            bookSeat(pickSeatIn);
        }
    }

    static void cancelSeat(String pickSeatIn) {
        System.out.print("Enter Seat Reservation: ");
        pickSeatIn = Keyboard.readString();

        if (toCancel(pickSeatIn)) {
            System.out.println(passName[i][j] + " your seat will be cancelled.");
        }
        else {
            System.out.println("This is not your seat");
        }

        System.out.println("Enter name");
        passName[i][j] = Keyboard.readString();

        if (!passName[i][j].equalsIgnoreCase(passName[i][j])) {
            System.out.println("wrong name");
        }
        showSeatMap();
    }

    static void printTicket() {
        System.out.println("Enter name");
        name = Keyboard.readString();
        System.out.println("Name: " + name);
        System.out.println("Seat Allocation: " + reservedSeat);
        System.out.println("Price:" + cost);
    }

    static boolean isSeatAvailable(String pickSeatIn) {
        for (i = 0; i < 30; i++) {
            for (j = 0; j < 6; j++) {
                if ((seatsArray[i][j]).equalsIgnoreCase(pickSeatIn)) {
                    seatsArray[i][j] = "X";
                    return true;
                }
            }
        }
        return false;
    }

    static boolean toCancel(String pickSeatIn) {
        for (i = 0; i < 30; i++) {
            for (j = 0; j < 6; j++) {
                if ((seatsArray[i][j]).equalsIgnoreCase("X")) {
                    seatsArray[i][j] = pickSeatIn.toUpperCase();
                    return true;
                }
            }
        }
        return false;
    }

    static void seatsRemaining() {
        count = 0;
        for (i = 0; i < 30; i++) {
            for (j = 0; j < 6; j++) {
                if (seatsArray[i][j].equals("X")) {
                    count++;
                }
            }
        }

        System.out.println("seats remaining =" + (180 - count));
    }
} 

在哪里,keyboard.nextString()表示无法找到任何人知道错误或如何解决这个问题的符号?我知道这将是一个非常容易修复的错误,但我不能破解它

1 个答案:

答案 0 :(得分:0)

您似乎缺少导入。你有没有在某处宣布Keyboard课程?如果是这样,请导入它。否则,请查看Scanner

Scanner sc = new Scanner(System.in);
String input = sc.next();