Guest User

Untitled

a guest
May 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Array {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. int numberOfEmployees; // will store the number of employees
  8. int compare; // number of employees you want to compare results to
  9.  
  10. //Scanner class enables user input
  11. Scanner sp = new Scanner(System.in);
  12.  
  13. System.out.println("Enter the number of employees: ");
  14. numberOfEmployees = sp.nextInt();
  15.  
  16. String[] employeeName = new String[numberOfEmployees]; // this string array will store the name of employees
  17. double[] AnnualSales = new double[numberOfEmployees]; // this will store the sales of every individual employee
  18.  
  19. for(int i = 0 ; i < numberOfEmployees ; i++) {
  20.  
  21. System.out.printf("Enter name of employee %d: ",i+1);
  22. employeeName[i] = sp.next();
  23.  
  24. System.out.printf("Enter salary of employee %d: ",i+1);
  25. AnnualSales[i] = sp.nextDouble();
  26.  
  27. }
  28.  
  29. System.out.println("Enter the number of employees you want to compare records of: ");
  30. compare = sp.nextInt();
  31.  
  32. if(compare > numberOfEmployees) {
  33.  
  34. System.out.println("IndexOutOfBound");
  35. System.exit(0);
  36. }
  37.  
  38. String[] comparison = new String[compare];
  39.  
  40. for(int i = 0; i < compare; i++) {
  41.  
  42. System.out.printf("Enter name of employee %d for comparison: ",i+1);
  43. comparison[i] = sp.next();
  44.  
  45. // a loop to go through all the names in the employeeName array
  46. System.out.println(comparison[i]);
  47.  
  48. for(int j = 0 ; j < numberOfEmployees ; j++) {
  49. if(comparison[i] != employeeName[j]) {
  50. System.out.println("Employee does not exist!");
  51. System.exit(0);
  52. }
  53. }
  54. }
  55.  
  56. // compare salary of 2 employees
  57.  
  58. if(AnnualSales[compare-1] > AnnualSales[compare-2]) {
  59.  
  60. System.out.printf("Sales of %s are greater than %s",employeeName[compare-1], employeeName[compare-2]);
  61. }else {
  62. System.out.printf("Sales of %s are less than %s",employeeName[compare-1], employeeName[compare-2]);
  63. }
  64.  
  65. sp.close();
  66. }
  67. }
Add Comment
Please, Sign In to add comment