Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
do {
            String sName;
            String sMission;
            
            System.out.printf("%-11s%-20s%10s\n", "*****", "Add the station in behind", "*****");
            System.out.print("Enter station name: ");
            sName = input.nextLine();
            System.out.flush();
            System.out.printf("%-15s\n%-15s\n%-15s\nYour Choice: ",
                    "Select station mission", "1.MCQ", "2.True/False Quiz");
            sMission = input.next();
            System.out.flush();

            if (sMission.equals("1")) {
                missionType = "|MCQ";
                r.addFront(sName + missionType);
            } else if (sMission.equals("2")) {
                missionType = "|Quiz";
                r.addFront(sName + missionType);
            } else {
                System.out.println("Invalid input must (1-2): ");
                Thread.sleep(2000);
                return;
            }
            //using overwrite to insert station
            File s = new File("Station.txt");

            try {
                if (s.exists() == false) {
                    s.createNewFile();
                }
                PrintWriter fw = new PrintWriter(s);
                fw.append(r.toString());//using toString to write to text file
                fw.close();
                System.out.println("Success to insert.");
            } catch (IOException e) {
                System.out.println("Could not create file");
            }
            System.out.printf("Continue(Y/N)?");
            selection = input.next();
        } while (selection.equals("y") || selection.equals("Y"));


Output:
***** Add the station in behind *****
Enter station name: Stt
Select station mission
1.MCQ
2.True/False Quiz
Your Choice: 1
Success to insert.
Continue(Y/N)?y
***** Add the station in behind *****
Enter station name: Select station mission //In here 2 while loop auto skip for enter station
1.MCQ
2.True/False Quiz
Your Choice: 3
Invalid input must (1-2):

Posted
Updated 28-Nov-15 20:25pm
v2
Comments
Richard MacCutchan 29-Nov-15 3:31am    
Just set a Boolean flag to indicate that some portion can be skipped.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900