Michitakaa2018

EmployeeDatabase.java

Nov 23rd, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  class EmpoyeeDatabase {
  4.     public static void main(String[] args) {
  5.  
  6.         Employee[] employees = {new Employee("Mario Nintendo", 41, "Actor", 220000.0), new Employee("Peach Nintendo", 21, "Actor", 210000.0), new Employee("Pacman Pacman", 20, "Actor", 230000.0), new Employee("Minecraft Minecraft", 10, "Gamer", 280000.0)};
  7.  
  8.         boolean stillRunning = true;
  9.         int choice;
  10.  
  11.         while (stillRunning == true) {
  12.  
  13.             choice = menuChoice();
  14.  
  15.             switch (choice) {
  16.                 case 1:
  17.                     printAllEmployees(employees);
  18.                     break;
  19.                 case 2:
  20.                     System.out.println(printEmployeeOfName(employees));
  21.                     enterToContinue();
  22.                     break;
  23.                 case 3:
  24.                     increaseSalary(employees);
  25.                     break;
  26.                 case 9:
  27.                     stillRunning = false;
  28.                     break;
  29.                 default:
  30.                     System.out.println("This number is invalid");
  31.             }
  32.  
  33.         }
  34.  
  35.         quitProgram();
  36.     }
  37.  
  38.  
  39.  
  40.    
  41.     private static int menuChoice(){
  42.         Scanner input = new Scanner(System.in);
  43.  
  44.         System.out.println("\n\n\nChoose a number and press Enter: \n");
  45.         System.out.println("********************************************************\n");
  46.         System.out.println("[1] Print all employees \t\t   [2] Print employee: enter name ");
  47.         System.out.println("[3] Print employee: enter age \t\t [4] Print employee: enter designation ");
  48.         System.out.println("[5] Print Employee: enter salary range \t\t [6] Increase employee salary" );
  49.         System.out.println("[9] Quit");
  50.         System.out.println("\n********************************************************");
  51.  
  52.         return input.nextInt();
  53.     }
  54.  
  55.     private static void printAllEmployees(Employee[] emps){
  56.         System.out.println("Here is a list of all employees: \n");
  57.         for (int i = 0; i<emps.length; i++){
  58.             System.out.println(emps[i]);
  59.         }
  60.  
  61.         enterToContinue();
  62.     }
  63.  
  64.     private static String printEmployeeOfName(Employee[] emps){
  65.  
  66.  
  67.         String name;
  68.  
  69.         boolean found = false;
  70.         Scanner input = new Scanner(System.in);
  71.  
  72.         System.out.println("Enter the name of the employee that you would like to find:");
  73.         name = input.nextLine();
  74.  
  75.  
  76.         for (int i=0;i<emps.length;i++){
  77.             if ((emps[i].getName()).equals(name)) {
  78.                 return emps[i].toString();
  79.             }
  80.  
  81.         }
  82.         return "Employee not found";
  83.  
  84.     }
  85.  
  86.     private static String printEmployeeOfAge(Employee[] emps){
  87.  
  88.         int age;
  89.         boolean found = false;
  90.         Scanner input = new Scanner(System.in);
  91.        
  92.        System.out.println("Enter the age of the employee that you would like to find:");
  93.         age = input.nextInt();
  94.  
  95.         for (int i=0;i<emps.length;i++){
  96.             if ((emps[i].getAge()) == age) {
  97.                 return emps[i].toString();
  98.             }
  99.  
  100.         }
  101.         return "Employee not found";
  102.  
  103.     }
  104.  
  105.    
  106.     private static void increaseSalary(Employee[] emps){
  107.         Scanner input = new Scanner(System.in);
  108.         String  name;
  109.         int percentage;
  110.         boolean employeeExists = false;
  111.         double currentSalary, newSalary;
  112.  
  113.         System.out.println("Enter the name of the employee that will receive a salary increase:");
  114.         name = input.nextLine();
  115.  
  116.         for(int i = 0;i<emps.length;i++){
  117.             if (emps[i].getName().equals(name)){
  118.                 employeeExists = true;
  119.                 System.out.println(name + "'s current salary is: " + emps[i].getSalary());
  120.                 System.out.println("Enter the percentage increase as am integer:");
  121.                 percentage = input.nextInt();
  122.  
  123.                 currentSalary = emps[i].getSalary();
  124.                 newSalary = currentSalary + ((percentage * currentSalary)/100);
  125.                 emps[i].setSalary(newSalary);
  126.  
  127.                 System.out.println("Current salary: " + currentSalary);
  128.                 System.out.println("New salary: " + newSalary);
  129.                 System.out.println("Salary increase: " + (newSalary - currentSalary));
  130.  
  131.             }
  132.         }
  133.         if (!employeeExists){
  134.             System.out.println("The employee you entered doesn't exist here.");
  135.         }
  136.         enterToContinue();
  137.  
  138.     }
  139.  
  140.     private static void enterToContinue(){
  141.         Scanner getEnter = new Scanner(System.in);
  142.         System.out.println("Press enter to continue");
  143.         getEnter.nextLine();
  144.     }
  145.  
  146.     private static void quitProgram(){
  147.         System.out.println("Thank you and goodbye!");
  148.     }
  149.  
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment