Skip to content

Commit

Permalink
Removed switch case. Added a dynamic method to get selected module an…
Browse files Browse the repository at this point in the history
…d execute the code for the same.
  • Loading branch information
vishal1201 committed Aug 27, 2018
1 parent b2767b3 commit c628631
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/com/company/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,32 @@ public static void main(String args[]) {

Scanner sc = new Scanner(System.in);
moduleIndex = sc.nextInt();
switch (moduleIndex) {
case 1:
executeChoice(moduleIndex);
break;
case 2:
executeChoice(moduleIndex);
break;
case 3:
executeChoice(moduleIndex);
break;
default:
System.out.println("Invalid choice");
EModule selectedModule = getSelectedModule(moduleIndex);
if (selectedModule != null) {
executeChoice(selectedModule);
} else {
System.out.println("Couldn't find corresponding module...");
}
}

private static void executeChoice(int index) {
System.out.println("Selected module index: " + index);
EModule selectedModule = getSelectedModule(index);
System.out.println("Starting module: " + selectedModule.name());
private static void executeChoice(EModule eModule) {
System.out.println("Starting module: " + eModule.name());
}

private static EModule getSelectedModule(int index) {
EModule selectedModule = null;
for (EModule eModule : EModule.values()) {
if (eModule.ordinal() + 1 == index) {
selectedModule = eModule;
EModule[] eModules = EModule.values();

if ((eModules.length < index) || index <= 0) {
System.out.println("Invalid index.");
return null;
} else {
for (EModule eModule : EModule.values()) {

This comment has been minimized.

Copy link
@vishal1201

vishal1201 Aug 27, 2018

Author Owner

replace by eModules in next commit.

if (eModule.ordinal() + 1 == index) {
selectedModule = eModule;
}
}
}

return selectedModule;
}

Expand Down

0 comments on commit c628631

Please sign in to comment.