#who know how to fix my while loop?

16 messages · Page 1 of 1 (latest)

mighty light
#

I guess this is Java, not into it, but your code does not make sense to me, you are initialising a variable called i but then inside your do clause you have the first check of the value of i but after that I see choice variable which is not declared at all?

shut monolith
mighty light
#

I would suggest that you pick up the input of the user and then use a SWITCH instead of IFs better.

shut monolith
#

let me fix the loop now

mighty light
#

what is your objective here? explain the exercise to me

shut monolith
#

i have a plan thats made let me send lol

#

creating a menu, jewellery database system

#

i have the classes all perfect.

mighty light
#

ahhh okay

shut monolith
#

just writing the loop now

#

i need a while loop a for loop and if else statements

#

i want to maybe nest the loop if that makes sense

#

whatever is easier for me bc im dying

#

i love gintama

mighty light
#

I would suggest not to use any loops here, have some functions for each of your modules and just call it

class Style {
    public void showOptions() {
        System.out.println("Options for Style:");
        // List Style-specific options here
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter a number (1 or 2): ");
        int choice = scanner.nextInt();

        switch (choice) {
            case 1:
                System.out.println("You chose to create. Pick an option:");
                System.out.println("1: Style\n2: Car\n3: Umbrella");
                int createChoice = scanner.nextInt();
                handleCreation(createChoice);
                break;
            case 2:
                System.out.println("You chose option 2.");
                // Implement option 2 functionality here
                break;
            default:
                System.out.println("Invalid initial choice.");
                break;
        }

        scanner.close();
    }

    private static void handleCreation(int choice) {
        switch (choice) {
            case 1:
                new Style().showOptions();
                break;
            default:
                System.out.println("Invalid option for creation.");
                break;
        }
    }

this is using the scanner, but you can use whatever you want