Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class EmployeeApp
- {
- static Scanner input = new Scanner(System.in);
- static InputStreamReader textInput = new InputStreamReader(System.in);
- static BufferedReader reader = new BufferedReader(textInput);
- static int centralEmployeeID = 105;
- static int centralDepartmentID = 1005;
- static ArrayList<Employee> allEmployee = new ArrayList<Employee>();
- static ArrayList<Department> allDepartments = new ArrayList<Department>();
- public static void main(String[] args)
- {
- prePopulate();
- mainMenu();
- }
- public static void prePopulate()
- {
- Department d1 = new Department(1001, "Sales");
- Department d2 = new Department(1002, "Production");
- Department d3 = new Department(1003, "Finance");
- Department d4 = new Department(1004, "Marketing");
- allDepartments.add(d1);
- allDepartments.add(d2);
- allDepartments.add(d3);
- allDepartments.add(d4);
- Employee e1 = new Employee(101, "Anton", 18, d1);
- Employee e2 = new Employee(102, "Dato", 17, d2);
- Employee e3 = new Employee(103, "Dyl", 19, d3);
- Employee e4 = new Employee(104, "Karl", 19, d4);
- d1.addEmployee(e1);
- d2.addEmployee(e2);
- d3.addEmployee(e3);
- d4.addEmployee(e4);
- allEmployee.add(e1);
- allEmployee.add(e2);
- allEmployee.add(e3);
- allEmployee.add(e4);
- }
- public static void mainMenu()
- {
- System.out.println("Press 1 for the Employee Menu");
- System.out.println("Press 2 for the Department Menu");
- System.out.println("Press 3 to Exit");
- String choice = input.next();
- switch(choice)
- {
- case "1":
- {
- System.out.println("Loading Employee Menu...");
- employeeMenu();
- break;
- }
- case "2":
- {
- System.out.println("Loading Department Menu...");
- departmentMenu();
- break;
- }
- case"3":
- {
- System.exit(0);
- break;
- }
- }
- mainMenu();
- }
- public static void departmentMenu()
- {
- System.out.println("Press 1 to Create a Department");
- System.out.println("Press 2 to View All Departments");
- System.out.println("Press 3 to Edit a Department");
- System.out.println("Press 4 to Delete a Department");
- System.out.println("Press 5 to Return to Main Menu");
- String choice = input.next();
- switch(choice)
- {
- case"1":
- {
- try {
- createDepartment();
- }
- catch(Exception e)
- {
- System.out.println("Error was logged");
- }
- break;
- }
- case"2":
- {
- viewDepartments();
- break;
- }
- case"3":
- {
- try {
- editDepartment();
- }
- catch(Exception e)
- {
- System.out.println("Error was logged");
- }
- break;
- }
- case"4":
- {
- deleteDepartment();
- break;
- }
- case"5":
- {
- mainMenu();
- break;
- }
- }
- }
- public static void employeeMenu()
- {
- System.out.println("Press 1 to Create a Employee");
- System.out.println("Press 2 to View All Employees");
- System.out.println("Press 3 to Edit a Employee");
- System.out.println("Press 4 to Delete a Employee");
- System.out.println("Press 5 to view Employees by Department");
- System.out.println("Press 6 to Return to Main Menu");
- String choice = input.next();
- switch(choice)
- {
- case"1":
- {
- try {
- createEmployee();
- }
- catch(Exception e)
- {
- System.out.println("Error was logged");
- }
- break;
- }
- case"2":
- {
- viewEmployees();
- break;
- }
- case"3":
- {
- try {
- editEmployees();
- }
- catch(Exception e)
- {
- System.out.println("Error was logged");
- }
- break;
- }
- case"4":
- {
- deleteEmployee();
- break;
- }
- case"5":
- {
- viewEmployeesByDepartment();
- break;
- }
- case"6":
- {
- mainMenu();
- break;
- }
- }
- }
- public static void createDepartment() throws Exception
- {
- Department d = new Department();
- d.setDepartmentID(centralDepartmentID);
- centralDepartmentID++;
- System.out.println("Enter Department Name");
- d.setDepartmentName(reader.readLine());
- allDepartments.add(d);
- System.out.println(d.getDepartmentName() + " has successfully been added");
- mainMenu();
- }
- public static void viewDepartments()
- {
- for(Department d: allDepartments)
- {
- System.out.println(d.getDepartmentID() + "\t" + d.getDepartmentName());
- }
- mainMenu();
- }
- public static void editDepartment() throws Exception
- {
- System.out.println("Please choose ID number of Department to edit");
- int chosenDepartment = input.nextInt();
- for(Department d: allDepartments)
- {
- if(chosenDepartment==d.getDepartmentID())
- {
- System.out.println("Enter Department Name");
- d.setDepartmentName(reader.readLine());
- System.out.println(d.getDepartmentName() + " has successfully been Edited");
- }
- }
- mainMenu();
- }
- public static void deleteDepartment()
- {
- System.out.println("Please choose ID number of Department to Delete");
- int chosenDepartment = input.nextInt();
- for(Department d: allDepartments)
- {
- if(chosenDepartment==d.getDepartmentID())
- {
- allDepartments.remove(d);
- System.out.println(d.getDepartmentName() + " has successfully been Deleted");
- mainMenu();
- }
- }
- }
- public static void createEmployee() throws Exception
- {
- Employee e = new Employee();
- e.setEmployeeID(centralEmployeeID);
- centralEmployeeID++;
- System.out.println("Enter Employee Name");
- e.setEmployeeName(reader.readLine());
- System.out.println("Enter Employee Age");
- e.setEmployeeAge(input.nextInt());
- System.out.println("Enter Employee Department");
- System.out.println("Enter Employee Department by using Department ID");
- int chosenDepartmentID = input.nextInt();
- for(Department d: allDepartments)
- {
- if(chosenDepartmentID == d.getDepartmentID())
- {
- e.setEmployeeDepartment(d);
- d.addEmployee(e);
- System.out.println(e.getEmployeeName() + " has applied for " + d.getDepartmentName());
- allEmployee.add(e);
- }
- }
- mainMenu();
- }
- public static void viewEmployees()
- {
- for(Employee e: allEmployee)
- {
- System.out.println(e.getEmployeeID() + "\t" + e.getEmployeeName() + "\t" + e.getEmployeeAge() + "\t" + e.getEmployeeDepartment().getDepartmentName());
- }
- mainMenu();
- }
- public static void editEmployees() throws Exception
- {
- System.out.println("Please choose Employee by ID Number");
- int chosenEmployee = input.nextInt();
- for(Employee e: allEmployee)
- {
- if(chosenEmployee==e.getEmployeeID())
- {
- System.out.println("Enter Employee Name");
- e.setEmployeeName(reader.readLine());
- System.out.println("Enter Employee Age");
- e.setEmployeeAge(input.nextInt());
- System.out.println("Enter Employee Department");
- System.out.println("Enter Employee Department by using Department ID");
- int chosenDepartmentID = input.nextInt();
- for(Department d: allDepartments)
- {
- if(chosenDepartmentID == d.getDepartmentID())
- {
- e.setEmployeeDepartment(d);
- d.addEmployee(e);
- System.out.println(e.getEmployeeName() + " has applied for " + d.getDepartmentName());
- System.out.println(e.getEmployeeName() + " has successfully been Edited");
- }
- }
- }
- }
- mainMenu();
- }
- public static void deleteEmployee()
- {
- System.out.println("Please choose ID number of Employee to Delete");
- int chosenEmployee = input.nextInt();
- for(Employee e: allEmployee)
- {
- if(chosenEmployee==e.getEmployeeID())
- {
- allEmployee.remove(e);
- System.out.println(e.getEmployeeName() + " has successfully been Deleted");
- mainMenu();
- }
- }
- }
- public static void viewEmployeesByDepartment()
- {
- System.out.println("Enter Department by ID number");
- int chosenDepartmentID = input.nextInt();
- for(Department d: allDepartments)
- {
- if(chosenDepartmentID == d.getDepartmentID())
- {
- d.printStaff();
- }
- }
- mainMenu();
- }
- public static void admin()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement