Skip to content
Permalink
Browse files

init assignment 2

  • Loading branch information...
bretonics committed Oct 10, 2018
1 parent 866f110 commit def237cae31297fb399faf8c3b385614bf4bc7bc
Showing with 215 additions and 0 deletions.
  1. +36 −0 CS665/Homework/ERP/ERP.java
  2. +58 −0 CS665/Homework/ERP/Menus.java
  3. +70 −0 CS665/Homework/ERP/Modules.java
  4. +51 −0 CS665/Homework/ERP/Prompt.java
@@ -0,0 +1,36 @@
/**
* ERP.java
* This is a ERP class
* @author Andres Breton
* @version 1.0
* Postcondition: Instantiate ERP module.
*/

import java.io.*;

public class ERP {

/**
* This is the main method controlling the ERP application.
* @param args Unused.
* @return Void.
* @exception IOException On input error.
* @see IOException
**/
public static void main(String[] args) throws IOException {

Menus welcome = new Menus("welcome");
welcome.printMenu();

while (true) {

// ERP module services
Modules modules = new Modules();
modules.init();
System.out.println(modules.module);
modules.launch();

}

} // ----------------------------- END OF MAIN -----------------------------
}
@@ -0,0 +1,58 @@
/**
* Menus.java
* This is a Menus class
* @author Andres Breton
* @version 1.0
* Postcondition: .
*/

class Menus {

// Instance variables
String[] menu;

// Class variables
String[] welcome = { "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
" Welcome! Entering the ERP system for Company.\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
};

String[] main = { "Enter new employee profile\n",
"Get employee information\n",
"Modify employee\n",
"See benefit offerings\n",
"Organization overview\n",
"Report issue\n",
};

// Default class constructor
Menus(String menu) {
switch (menu) {
case "main":
this.menu = main; break;
case "welcome":
this.menu = welcome; break;
default:
this.menu = main; break;
}
}


/** CLASS METHODS **/

// Get menu type array
protected String[] getMenu() {
return menu;
}

// Print menu
protected void printMenu() {
int n = 1;
System.out.println("");
for (String line: menu) {
System.out.println(line);
}
System.out.println("");
}
}
@@ -0,0 +1,70 @@
/**
* Module.java
* This is a Module class
* @author Andres Breton
* @version 1.0
* Postcondition: .
*/

import java.util.Arrays;

class Modules {
enum Types { HR, ACCOUNTS, MARKETING };

// Instance variables
String module;
Types[] types;

// Default class constructor
protected Modules() {
this.types = Types.values();
};

// Class constructor
// private Modules(String module) {
// this.module = module.toUpperCase();
// }


/** CLASS METHODS **/
//

protected void init(){
String[] types = convert();
Prompt prompt = new Prompt(types);
Integer choice = prompt.askChoice();
setModule(types[choice-1]);
}

protected void setModule(String module) {
this.module = module;
}

// Get all available modules
protected Types[] getModules() {
return Types.values();
}

//


// Launch ERP module selected
protected void launch() {
System.out.println("\nLaunching " + module + "...\n");
switch(module) {
case "HR":
HR.main(); break;
// case "ACCOUNTS":
// Accounts.main(); break;
// case "MARKETING":
// Marketing.main(); break;
}
}

private String [] convert() {
String [] arr;
arr = Arrays.stream(Types.values()).map(Enum::toString).toArray(String[]::new);
return arr;
}
}
@@ -0,0 +1,51 @@
/**
* Prompt.java
* This is a Prompt class showing a request
* @author Andres Breton
* @version 1.0
* Postcondition: Prompt object created.
*/
import java.util.*;

class Prompt {

// Instance variables
String[] options;
String choice;

// Default class constructor
protected Prompt(String[] options) {
this.options = options;
this.choice = choice;
}


/** CLASS METHODS **/

/**
* This method asks users for menu choice.
* @param NULL
* @return Integer of choice selected.
*/
protected Integer askChoice() {
Scanner input = new Scanner(System.in);
Integer choice = null;

// Ask user for numeric menu choice
Integer numOptions = options.length;
while ( choice == null || choice <= 0 || choice > numOptions ) {
int n = 1;
System.out.println("\nPlease select:\n");
for (int i = 0; i < numOptions ; i++) {
System.out.println("\t" + n + ". " + options[i]);
n++;
}
System.out.println("");
choice = input.nextInt(); // get user input
}
return choice;
}


}

0 comments on commit def237c

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.