user1935321
user1935321

Reputation: 23

Running the program without ending it

how can i select 1 or 2 or 3 and after running the program back to select option menu ... i dont want my program ending after select 1 or 2 how can i do that ... thanks in advance.

this is my selecting option program ...

public class Dialog
{

        AddList ad = new AddList();
        int select;
        void showDialog()
        {
            System.out.println("Enter The 1 for addnig data");
            System.out.println("Enter The 2 for Waching the MARK data");
            System.out.println("Enter The 3 for Waching the NAME data");
            System.out.println("Enter The 4 for Waching All the data of students");
            System.out.println("Enter The 5 for Waching SUM of the mark of Students");
        }

        void progressInput()
        {

            Scanner scan = new Scanner(System.in);
            select = scan.nextInt();

            if (select == 1)
            {
                ad.AddListIntoArray();
            }
            else if (select == 2)
            {
                ad.PrintMarkFromTheArray();
            }
            else if (select == 3)
            {
                ad.PrintNameFromTheArray();
            }
            else if (select == 4)
            {
                ad.PrintNameMarkFromTheArray();
            }
            else if (select == 5)
            {
                ad.SendMark();
            }
            else
            {
       System.out.println("Please Input range from 1 to 5 and not something else");
            }
        }
}

and this is my main program .... everything here is ok but i dont want my program end after selecting 1 or 2 i mean the program 1 execute and show the result and back to the select option menu ...

public class Main
{

    public static void main(String[] args)
    {

         Dialog dlg = new Dialog();
         dlg.showDialog();
         dlg.progressInput();

    }

}

Upvotes: 0

Views: 80

Answers (2)

vels4j
vels4j

Reputation: 11298

Add

System.out.println("Enter The 1 for addnig data");
System.out.println("Enter The 2 for Waching the MARK data");
System.out.println("Enter The 3 for Waching the NAME data");
System.out.println("Enter The 4 for Waching All the data of students");
System.out.println("Enter The 5 for Waching SUM of the mark of Students");
System.out.println("Enter The 6 for Exit");

then

Scanner scan = new Scanner(System.in);
int select = 0;
do {
    System.out.println("Enter your option");
    select = scan.nextInt();
    if (select == 1) {
        ad.AddListIntoArray();
    } else if (select == 2) {
        ad.PrintMarkFromTheArray();
    } else if (select == 3) {
        ad.PrintNameFromTheArray();
    } else if (select == 4) {
        ad.PrintNameMarkFromTheArray();
    } else if (select == 5) {
        ad.SendMark();
    }else if (select == 6) {
        System.out.println("Exiting...");
    }
    else {
        System.out.println("invalid input");
    }
} while (select != 6);

Upvotes: 0

Subhrajyoti Majumder
Subhrajyoti Majumder

Reputation: 41210

put your code inside while(true) loop.

Dialog dlg = new Dialog();
while(true){
    dlg.showDialog();
    dlg.progressInput();
}

Upvotes: 2

Related Questions