0

I'm making a "Tinder4Food" program/project where it offers you two or more foods and then the user chooses one. Right now there is a selection of only 3 foods since I want to get the basics done. After you choose the food, it asks you if you are done and want to go to your review page where you see all the foods you liked. Like I said earlier, there are only 3 foods so it will only list 1 or 2 foods. So, you either choose, yes, I want to go to my review page or no, I don't. That's where the problem is. If the user says no, I want it to repeat the method where it shows you the choices of food and you choose one of them. After that, it will direct you back to the review question and so on...

I've looked on the web and I saw while loops are the best. I've tried that but it still doesn't work. Maybe I'm doing something wrong.


import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.lang.String;
import java.util.Scanner;



public class Main {

    public int food() {
        return food();

    }

    public static void main(String[] args) {


        List<String> foodList = new ArrayList<String>();

        //random foods getting listed
        Random rand = new Random();

        int x = rand.nextInt(3) + 1;
        int l = rand.nextInt(3) + 1;

        System.out.print("Which food do you want?");
        foodList.add("pizza");
        foodList.add("burger");
        foodList.add("fries");

        System.out.println("In our menu today we have " + foodList.get(0) + " " + foodList.get(1) + " " + foodList.get(2));


            Scanner food = new Scanner(System.in);
            int n = food.nextInt();
            String input = food.nextLine();
            String array[] = input.split(" ");
            // ask discord for help about using an if else statement for this.

            int f = 1;
            int z = 2;
            int y = 3;

            System.out.println(f + " is " + foodList.get(0) + " " + z + " is " + foodList.get(1) + " " + y + " is " + foodList.get(2));
            // f is equal to pizza
            // int z is equal to burger
            // int y is equal to fries


            if (n == f) {
                System.out.println(foodList.get(0) + " will be added to your good list");

            }

            if (n == z) {

                System.out.println(foodList.get(1) + " will be added to your good list!");
            }

            if (n == y) {

                System.out.println(foodList.get(2) + " will be added to your good list!");


            }



            System.out.println("Is this your final choice?");

            Scanner end = new Scanner(System.in);
            int k = end.nextInt();
            String choice = food.nextLine();
            String endchoice[] = input.split(" ");


            int b = 1;
            int v = 2;
            // b is equal to yes. v is equal to no.

            if (k == b) {
                System.out.println("Okay, this is your good list " + n);


            }

            if (k == v) {

                System.out.println("Okay. We will keep going ");


            }
        }
    }



Everything works well until the last part. I mentioned it earlier and I will do it again just in case you want to know. I want to repeat the method that asks you which food you want. After that, direct you back to the question that asks you if you are done and want to go to your review page or keep going. The end question method is the two if statements at the bottom. I'm specifically talking about the if statement where it says if (k == v). There are some other bugs like when you answer the last questions, you have to type the number of what the int is set to and then the int letter.

It would be awesome if you could help. I'm not that new to java but somethings I just don't know really well yet. I'm only 13 tryna learn how to code. Thank you!!!

  • @GBlodgett Honestly, I don't think that's it... Thanks for the help though I guess. I looked at it and it doesn't look like it will answer my question. Btw I don't think it's a duplicate. It's talking about something else. – Eldar Ulanov Mar 25 '19 at 20:48
  • Create a variable: boolean continue = true; wrap the whole thing in a while(continue) and if you want it to stop, simply in the iff (k==v) do "continue = false;" – JustAFellowCoder Mar 25 '19 at 20:50
  • Hi Eldar! Welcome to Stack Overflow! If you want to know more about loops I'd read [this](https://www.geeksforgeeks.org/loops-in-java/) – GBlodgett Mar 25 '19 at 21:04

0 Answers0