程序在netbeans中完成并且工作正常但是当剪切并粘贴到记事本然后编译将无法正常工作

时间:2015-10-10 04:42:59

标签: java netbeans cmd

我在netbeans中创建了一个程序,程序中的所有选项都有效但是当我把代码粘贴到记事本然后在cmd编译它时,一些选项可以正常工作而有些选项不起作用,为什么会这样? / p>

let tablesQuery = app.tables
app.navigationBars["LandingScreen"].buttons["Hamburger"].tap()
  tablesQuery.staticTexts["alwaysShownButton"].tap()

app.navigationBars["alwaysAccessibleScreen"].buttons["Hamburger"].tap()
  tablesQuery.staticTexts["sometimesHiddenButton"].staticTexts.tap() <-fails

以下是其他代码:

import java.io.FileNotFoundException;
import java.util.Scanner;

/*
You should create at least 2 Java classes – Titanic and TestTitanic
 */
public class TestTitanic{

    public static void main(String[] args) throws FileNotFoundException {
        //Use command line arguments to send in the name of the Titanic file
        String fileName = args[0];
        Titanic titanic = new Titanic(fileName);
        //The application should keep track of the elapsed time (in seconds) 
        long startTime = System.currentTimeMillis();

        //A user-friendly and well-organized menu s
        String choices[] =
        {"Total number of passengers on the Titanic",
            "Total number of passengers who perished on the Titanic",
            "Total number of Passengers who survived the sinking of the Titanic",
            "Number of passengers who survived the sinking of the Titanic as a function of the passenger class (e.g. 1,2,3)",
            "Number of passengers who survived the sinking of the Titanic as a function of the passenger gender (e.g., male, female)",
            "A list of the names of passengers who paid greater than $200 for their tickets",
            "A list of the names of passengers who were less than 10 years old who survived",
            "A list of the names of passengers who were less than 10 years old who perished ",
            "The count of the number of passengers as a function of the first letter of their last name. (e.g., A: 13, B:33 …)", "Exit"};
        int choice = menuChoice(choices);
        while (choice != 10) {
            switch (choice) {
                case 1:
                    System.out.println("Total number of passengers on the Titanic: " + titanic.getTotalPassengers());
                    break;
                case 2:
                    System.out.println("Total number of passengers who perished on the Titanic: " + titanic.getTotalNumberofPerishedPassengers());
                    break;
                case 3:
                    System.out.println("Total number of passengers who survived : " + titanic.getTotalNumberofSurvivedPassengers());
                    break;
                case 4:
                    System.out.print("Enter class (e.g. 1,2,3): ");
                    int cls = getIntInRange(1, 3);
                    System.out.println(cls + " class number of passengers who survived: " + titanic.getTotalNumberofSurvivedPassengersByClass(cls));
                    break;
                case 5:
                    System.out.print("Enter gender (e.g., male, female): ");
                    String gender = getString();
                    System.out.println("Number of " + gender + " passengers who survived: " + titanic.getTotalNumberofSurvivedPassengersByGender(gender));
                    break;
                case 6:
                    System.out.print("Names of passengers who paid greater than $200 for their tickets: ");
                    System.out.println(titanic.getNamesPaidFare(200));
                    break;
                case 7:
                    System.out.print("Names of passengers who were less than 10 years old who survived: ");
                    System.out.println(titanic.getSurvivedNamesLessGivenAge(10));
                    break;
                case 8:
                    System.out.print("Names of passengers who were less than 10 years old who perished: ");
                    System.out.println(titanic.getPerishedNamesLessGivenAge(10));
                    break;
                case 9:
                    System.out.print("Enter the letter: ");
                    char ch = getString().charAt(0);
                    System.out.println("Count: " + titanic.getCountByFirstLetterOfFirstName(ch));
                    break;
            }
            choice = menuChoice(choices);
        }

        //The application should keep track of the elapsed time (in seconds) 
        long endTime = System.currentTimeMillis();
        long elapsedTime = (endTime - startTime) / 1000;
        /**
         * After the program is exited, the application should provide a prompt
         * thanking the user for trying the Titanic program and providing the
         * total time elapsed.
         */
        System.out.println("Thank you for trying the Titanic program");
        System.out.println("Elapsed time: " + elapsedTime);
    }

    /**
     * Helper method to get String from user
     *
     * @return
     */
    public static String getString() {
        Scanner input = new Scanner(System.in);
        return input.nextLine();
    }

    /**
     * Helper method to get user input in range
     *
     * @param low
     * @param high
     * @return
     */
    public static int getIntInRange(int low, int high) {
        int num = 0;
        do {
            num = getInt();
            if (num < low || num > high) {
                System.out.println("Enter number between " + low + " and " + high);
            }
        } while (num < low || num > high);
        return num;
    }

    /**
     *
     * method to display organized menu to user
     *
     * @param choices
     * @return
     */
    public static int menuChoice(String choices[]) {
        int choice = 0;
        System.out.println("");
        for (int i = 0; i < choices.length; i++) {
            System.out.println((i + 1) + ". " + choices[i]);
        }
        System.out.print("Enter choice (1-" + choices.length + "): ");
        choice = getIntInRange(1, choices.length);
        return choice;
    }

    /**
     * Helper method to get int from user
     *
     * @return
     */
    public static int getInt() {
        Scanner input = new Scanner(System.in);
        int num = -1;
        boolean good;
        do {
            good = true;
            try{
                num = input.nextInt();
            }

            catch(Exception e) {
                good = false;
                input = new Scanner(System.in);
                System.out.println("Enter numeric value: ");
            }
        } while (!good);
        return num;
    }
}

这是stacktrace:

  

线程中的异常&#34; main&#34; java.lang.ArrayIndexOutOfBoundsException:1在Titanic.getTotalNumbersofPerishedPassengers(Titanic.java:43)在TestTitanic.main(TestTitanic.java:34)

0 个答案:

没有答案