samedi 22 février 2020

User input is not calling method (Java)

When I run my program and type user input as (A-F) the program does nothing. I'm trying to figure out why when I enter any of the letters A through Z the program doesn't call the method. If I input one of the numbers they will run perfectly fine and call the methods, but the letters are giving me problems for some reason.

public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    String userInput;
    initializeShipList();       // initial ships
    initializeCruiseList();     // initial cruises
    initializePassengerList();  // initial passengers

    // add loop and code here that accepts and validates user input
    // and takes the appropriate action. include appropriate
    // user feedback and redisplay the menu as needed
    do {
        displayMenu();
        userInput = scnr.nextLine();
        if(userInput.equals("1")) {
            addShip();
        }
        if(userInput.equals("2")) {
            editShip();
        }
        if(userInput.equals("3")) {
            addCruise();
        }
        if(userInput.equals("4")) {
            editCruise();
        }
        if(userInput.equals("5")) {
            addPassenger();
        }
        if(userInput.equals("6")) {
            editPassenger();
        }
        if(userInput.toUpperCase().equals("A")) {
            printShipList("active");
        }
        if(userInput.toUpperCase().equals("B")) {
            printShipList("name");
        }
        if(userInput.toUpperCase().equals("C")) {
            printShipList("full");
        }
        if(userInput.toUpperCase().equals("D")) {
            printCruiseList("list");
        }
        if(userInput.toUpperCase().equals("E")) {
            printCruiseList("details");
        }
        if(userInput.toUpperCase().equals("F")) {
            printPassengerList();
        }
    }while(userInput != "x"); 
  }

Aucun commentaire:

Enregistrer un commentaire