mercredi 15 mai 2019

Main will not call array

I made an array to randomly pick either "steak, pizza, or chips" but I upon running my program it errors out well before you even get to the question. It works for about 5 inputs before it gives me an exception.

I assume the problem lies within the

{System.out.println(FoodArray.getRandomWord(args));

but I can't seem to figure out what is wrong with it.

I just need my program to run correctly, and when it gets to the question about giving a random suggestion, it prints out steak, pizza or chips randomly.

public static void main(String[] args) {

    int input = 0;
    int sweet = 0;
    int savory = 0;
    int salty = 0;

    Random r = new Random();

    FoodArray a = new FoodArray();

    Scanner myscanner = new Scanner(System.in);
    System.out.println("Welcome, lets figure out what you're hungry for."
            + "Press 0 to continue");
    input = myscanner.nextInt();
    if (input > 0) {

    }

    {
        System.out.println("What sounds the best to you right now?\n"
                + "1) Something sweet\n"
                + "2) Savory\n "
                + "3) Salty\n ");
    }
    input = myscanner.nextInt();

    if (input == 1) {
        System.out.println("something sweet. okay. next question");
        sweet++;
    } else if (input == 2) {
        System.out.println("Savory eh? got it. lets move on.");
        salty++;
    } else if (input == 3) {
        System.out.println("Sounds good. Lets proceed");
        savory++;
    }
    System.out.println("Press 0 to continue");

    input = myscanner.nextInt();

    System.out.println("pick a number 1-3");

    input = myscanner.nextInt();

    if (input == 1) {

        System.out.println("Very interesting.");
        sweet++;
    } else if (input == 2) {
        System.out.println("Very interesting.");
        salty++;
    } else if (input == 3) {
        System.out.println("Very interesting.");
        savory++;
    }

    System.out.println("Press 0 to continue");
    input = myscanner.nextInt();

    System.out.println("Next question: "
            + "Would you rather, fly, (1) breath underwater, (2) or be invisible (3)");
    input = myscanner.nextInt();

    if (input == 1) {
        System.out.println("Good choice.");
        sweet++;

    }
    if (input == 2) {
        System.out.println("Would be pretty cool");
        salty++;
    }

    if (input == 3) {
        System.out.println("Trick question, you already are invisible loser."
                + "Lets continue. ");
        savory++;

    }

    System.out.println("Okay. now heres a random suggestion.");
  {System.out.println(FoodArray.getRandomWord(args));
}


    System.out.println("Okay. Lets see your final score."
            + "Press 0 to continue");

    input = myscanner.nextInt();

    if (sweet > salty && sweet > savory) {
        System.out.println("Get something sweet. maybe cake.");
    }

    if (salty > sweet && salty > savory) {
        System.out.println("Get something salty. Maybe potatoe chips");

    }

    if (savory > sweet && savory > salty) {
        System.out.println("Savory! Steak steak steak!");
    }

    if (salty == sweet && salty == savory) {
        System.out.println("Its a tie. Can't help you. sorry.");
    }

    if (sweet == salty && sweet == savory) {
        System.out.println("Its a tie. Can't help you. sorry.");
    }

    if (savory == sweet && savory == salty) {
        System.out.println("Its a tie. Can't help you. sorry.");
    }

}

}




Aucun commentaire:

Enregistrer un commentaire