[英]How declare subcategory java
我想为此选项创建一个子类别。 我无法创作。 当我 select 1 时,我希望它显示几个子类别。
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:");
}
}
}
}
所以当我选择 1 我想显示 1... , 2... , 3.... , 4....
但是,您的程序有很多拼写错误和语法错误,但至少您做了一些事情并在这里提供了代码,这很好。
这段代码不是最好的,但我认为它会帮助你:)
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 ) ;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.