简体   繁体   中英

How declare subcategory java

I want to create a subcategory for this option. I can't create. When I select 1, I want it to show me a few subcategories.

package Javaapplication7;

import java.util.ArrayList;
import java.util.Scanner;

public class JavaApplication7 {

        static Scanner input = new Scanner (System.in);
        static ArrayList<Employee> emplList = new ArrayList<Employee>();

        public static void main(String[] args) {
            while(true) {

                System.out.println("1.Register employee");
                System.out.println("2View employee");
                System.out.println("3.Remove employee");
                System.out.println("4.Generate payslips");
                System.out.println("5.Exit");
                System.out.println("input option: ");
                int option = input.nextInt(); input.nextLine();



                switch(option){     
                    case 1:    
                        System.out.println("Register is selected ");
                        System.out.println("provide name: ");
                        String name = input.nextLine();
                        double salary= input.nextInt(); input.nextLine();
                        Employee emp = new employee(name,salary);
                        emplList.add(emp);
                        System.out.println("Regsitered:");
                }
            }
        }

}

So when I choose 1 I want to show 1... , 2... , 3.... , 4....

However your program have so many typo and syntax error but its nice at least you done something and come up here with code.

this code is not so best but i think it will help you:)

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Test {
 static Scanner input = new Scanner (System.in);


public static void main(String[] args) throws IOException {



    int inputOption;
    do { 

        System.out.println("Choose Your Option :");
        System.out.println("1.Register employee");
        System.out.println("2. View employee");
        System.out.println("3.Remove employee");
        System.out.println("4.Generate payslips");
        System.out.println("5.Exit");
        System.out.println("input option: ");

       inputOption = input.nextInt(); 


       switch (inputOption) {
            case 1:


                System.out.println("Register is selected ");
                System.out.println("Do your Task"); 

                System.out.println("Choose Your Option :");
                System.out.println("1.Option 1");
                System.out.println("2.Option 2"); 
                System.out.println("5.Exit"); //keep 5 for exit
                System.out.println("input option: ");

                int inputSubOption = input.nextInt(); 

                switch (inputSubOption) {
                case 1:
                        System.out.println("1 Sub category Taks");
                        System.out.println("Press any number other then 5 to continue.....");
                        int exit = input.nextInt();
                        if( exit ==5 ) {System.exit(0); }
                    break;
                case 2:
                    System.out.println("2 Sub category Taks");
                break;

                default:
                    break;
                }

                break;

            default:
                break;
       }


    } while ( inputOption !=5 ) ;



}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM