실행 클래스
import java.util.Scanner;
import java.util.EnumSet;
public class ITAssetManagementSystem { //main class to execute
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = 0; //The number to control main menu
while(N != 9){
System.out.println("IT Asset Management System"); // Displaying the main menu
for(MainMenuEnum menu:MainMenuEnum.values()) { // and asking the number
System.out.printf("%d. %s%n", menu.getNum(), menu.getOption()); //
} //
System.out.print("Enter choice: "); //
N = sc.nextInt(); //input the number where user want to go
System.out.println();
MainMenuEnum mm; // bring the enum of main menu
if(N==1){ //the case of "Register Asset"
mm = MainMenuEnum.RA; //enter the "Register Asset" menu, so assign the value of Register Asset
int M = 0; //the number to control register menu
while(M !=3 ) { //repeat until user choose "Back to main menu"
System.out.printf("%s%n",mm.getOption());
for (RegisterAssetMenuEnum menu : RegisterAssetMenuEnum.values()) { //Displaying Register menu
System.out.printf("%d. %s%n", menu.getNum(), menu.getOption()); //
}
System.out.print("Enter choice: "); //and asking the number
M = sc.nextInt(); //input the number where user want to go
RegisterAssetMenuEnum RA; //bring the enum of register menu
if (M == 1) { //the case of "Hardware"
RA = RegisterAssetMenuEnum.HW; //enter the "Hardware" menu, so assign the value of Hardware
System.out.println("Hardware registration is under development.");
System.out.println();
} else if (M == 2) {
RA = RegisterAssetMenuEnum.SW;
System.out.println("Software registration is under development.");
System.out.println();
} else if (M == 3) {
RA = RegisterAssetMenuEnum.BMM;
System.out.println();
}else{ // the case of mistake that user enter other numbers
System.out.println("Invalid choice. Please try again.");
System.out.println();
} //The rest is a repetition of the methods up to this point.
}
} else if(N==2){ //the case of "Search Assets"
mm = MainMenuEnum.SA;
int L =0;
while(L !=4 ) {
System.out.printf("%s%n",mm.getOption());
for (SearchAssetMenuEnum menu : SearchAssetMenuEnum.values()) {
System.out.printf("%d. %s%n", menu.getNum(), menu.getOption());
}
System.out.print("Enter choice: ");
L = sc.nextInt();
SearchAssetMenuEnum SA;
if (L == 1) {
SA = SearchAssetMenuEnum.FS;
System.out.println("Full asset search is under development.");
System.out.println();
} else if (L == 2) {
SA = SearchAssetMenuEnum.BH;
System.out.println("Hardware asset search is under development.");
System.out.println();
} else if (L == 3) {
SA = SearchAssetMenuEnum.BS;
System.out.println("Software asset search is under development.");
System.out.println();
} else if (L == 4) {
SA = SearchAssetMenuEnum.BMM;
System.out.println();
}else{ // the case of mistake that user enter other numbers
System.out.println("Invalid choice. Please try again.");
System.out.println();
}
}
} else if(N==9){ //the case of "Exit"
mm = MainMenuEnum.ET;
System.out.println("Exiting...");
}else{ // the case of mistake that user enter other numbers
System.out.println("Invalid choice. Please try again.");
System.out.println();
}
}
}
}
메인메뉴 Enum
public enum MainMenuEnum {
RA(1, "Register Asset"),
SA(2, "Search Assets"),
ET(9, "Exit");
private final int num;
private final String option;
MainMenuEnum(int num, String option){
this.num = num;
this.option = option;
}
public int getNum(){
return num;
}
public String getOption(){
return option;
}
}
register asset 메뉴 Enum
public enum RegisterAssetMenuEnum {
HW(1, "Hardware"),
SW(2, "Software"),
BMM(3, "Back to Main Menu");
private final int num;
private final String option;
RegisterAssetMenuEnum(int num, String option){
this.num = num;
this.option = option;
}
public int getNum(){
return num;
}
public String getOption(){
return option;
}
}
search asset 메뉴 Enum
public enum SearchAssetMenuEnum {
FS(1, "Full Search"),
BH(2, "By Hardware"),
BS(3, "By Software"),
BMM(4,"Back to Main Menu");
private final int num;
private final String option;
SearchAssetMenuEnum(int num, String option){
this.num = num;
this.option = option;
}
public int getNum(){
return num;
}
public String getOption(){
return option;
}
}