Question
How to fix the code with these suggestions Classes should not be static. Each class should be inside a separate file with a public class.
How to fix the code with these suggestions
Classes should not be static. Each class should be inside a separate file with a public class. There should be a separate class file with the main method, that should use all those reusable classes in the design. Such as Employee, Branch, and Manager.
public class Assignment11 { public static void main (String args[]) { int var = 0; int e = 0; String def = "a"; Scanner input = new Scanner(System.in); System.out.print("Hello and welcome to employee staffing and organization program."); System.out.println("The purpose of this program is to organize the labor force at multiple offices nation or worldwide."); System.out.println("First, please enter the number of locations you have."); int a = input.nextInt(); System.out.println("Excellent! You have " + a + " branches of your company established."); System.out.println("What is the maximum number of employees that can be staffed at any location?"); int b = input.nextInt(); b = b+2; int d = 0; Object [][][] n = new Object [a+1][b+7][5]; Object [] temp = new Object[5]; String s = "l"; for (int c = 0; c < a; c++) { System.out.println("Please enter the name of location number " + (c+1)); input.nextLine(); s = input.nextLine();
branch y = new branch (s,var); n [c][0][0] = y.getloc(); int w1 = 0; while (w1 ==0) { System.out.println("Excellent! Please enter the 4-digit branch ID for " + n [c][0][0]); d = input.nextInt(); w1 = d/1000; if ((w1 > 10)||(w1<1)) { System.out.println("The user input is invalid. Please try again."); w1 = 0; } } branch y1 = new branch(def, d); n [c][0][1] = y1.getLocID(); System.out.println("You will now assign a manager for the " + n[c][0][0] + " location."); System.out.println("Please enter the first name of the manager for this location."); input.nextLine(); s = input.nextLine(); manager y2 = new manager (s, var); n [c][1][0] = y2.getManame(); System.out.println("Now please enter the last name of the manager of this location."); s = input.nextLine(); manager y3 = new manager (s, var); n [c][1][1] = y3.getManame(); w1 = 0; while (w1 == 0) { System.out.println("Excellent! Please enter the 4-digit manager ID for " + n [c][1][0] + " " + n[c][1][1]); d = input.nextInt(); w1 = d/1000; if ((w1 > 10)||(w1<1)) { System.out.println("The user input is invalid. Please try again."); w1 = 0; } } manager y4 = new manager (def, d); n [c][1][2] = y4.getManID(); n [c][1][3] = "hired"; System.out.println("Now enter the number of employees that work at " + n [c][0][0]); e = input.nextInt(); employee yy = new employee(def, e); n [c][0][2] = yy.getID(); System.out.println("Excellent! " + e + " employees work in " + n[c][0][0]); for (int f = 2; f < (e+2); f++) { System.out.println("Please enter the first name of employee number " + (f-1)); input.nextLine(); s = input.nextLine(); employee y5 = new employee (s, var); n [c][f][0] = y5.getStatus(); System.out.println("Now enter their last name."); s = input.nextLine(); employee y6 = new employee (s, var); n [c][f][1] = y6.getStatus(); w1 = 0; while (w1 == 0) { System.out.println("Excellent! Please enter the 4-digit employee ID for " + n [c][f][0] + " " + n[c][f][1]); d = input.nextInt(); w1 = d/1000; if ((w1 > 10)||(w1<1)) { System.out.println("The user input is invalid. Please try again."); w1 = 0; } } employee y7 = new employee (def, d); n [c][f][2] = y7.getID(); n [c][f][3] = "hired"; } } System.out.println("Here is a summary of the user input"); for (int g = 0; g < a; g++) { System.out.print("Location " + (g+1) + ": " + n[g][0][0]); System.out.println(" - ID: " + n[g][0][1]); System.out.println(); System.out.println("Manager: " + n[g][1][0] + " " + n[g][1][1]); System.out.println(); System.out.println("Employees:"); for (int h = 2; h < b; h++) { if (n [g][h][3] == "hired") { System.out.println(n[g][h][0] + " " + n[g][h][1] + " - " + n[g][h][2]); } } }
int j = 0; int zaza = 1; while (zaza == 1) { int i = 1; while (i == 1) { i++; System.out.println("What would you like to do?"); System.out.println("1 - Promote an employee to manager"); System.out.println("2 - Demote a manager to employee"); System.out.println("3 - Move member of staff to another location."); System.out.println("4 - Fire a member of staff"); j = input.nextInt(); if ((j <= 0) || (j > 4)) { System.out.println("The user input is invalid. Please try again."); i = 0; } } int l = 0; int whil = 0; while (whil == 0) { whil++; System.out.println("Which location does the particular member of staff work at?"); for (int k= 0; k < a; k++) { System.out.println((k+1) + " - " + n[k][0][0]); } l = input.nextInt(); if (l > a || l < 1) { System.out.println("The user input is invalid. Please try again"); whil = 0; } } l = l-1; switch (j) { case 1: System.out.println("Please select the employee you would like to promote."); for (int m = 2; m-2 < (int)n[l][0][2]; m++) { System.out.print((m-1) + " - " + n[l][m][0] + " " + n [l][m][1] + ": " + n [l][m][2]); if (n[l][m][3] == "fired") { System.out.println("- fired"); } } int o = input.nextInt(); o = o+1; System.out.println("Excellent! You have decided to promote " + n[l][o][0] + " " + n [l][o][1] + "."); if (n[l][1][3] == "hired") { System.out.println("The manager position at this location has already been filled. In order to promote an employee, you will have to either demote or fire the current manager."); int p = 0; while (p == 0) { p++; System.out.println("Would you like to:"); System.out.println("1 - Demote"); System.out.println("2 - Fire"); int q = input.nextInt(); switch (q) { case 1: break; case 2: n [l][1][3] = "fired"; break; default: System.out.println("The user input is incorrect. Please try again."); p=0; } } } System.out.println("Excellent!"); for(int r = 0; r < 4; r++) { temp [r] = n[l][1][r]; n[l][1][r] = n[l][o][r]; n[l][o][r] = temp [r]; } break; case 2: int z = 0; int u = 0; while (u==0) { System.out.println("In order to demote " + n [l][1][0] + " " + n[l][1][1] + ", you must promote one of your employees to fill the open position."); System.out.println("Which employee would you like to promote?"); for (int v = 2; v-2 < (int)n[l][0][2] ; v++) {
System.out.print((v-1) + " - " + n[l][v][0] + " " + n[l][v][1]); if (n[l][v][3] == "fired") { System.out.println(" - fired"); }else { System.out.println(); } } u++; z = input.nextInt(); z++; if (n[l][z][3] == "fired") { System.out.println("Warning! The employee you selected has been fired. Are you sure you want to fill a manager position with a fired employee?"); System.out.println("1 - Yes"); System.out.println("2 - No"); int zz = input.nextInt(); switch (zz) { case 1: break; case 2: System.out.println("Ok, please select another employee."); u = 0; break; } } } for (int aa = 0; aa < 4; aa++) { temp [aa] = n[l][1][aa]; n[l][1][aa] = n[l][z][aa]; n[l][z][aa] = temp [aa]; } break; case 3: System.out.println("To which location would you like to transfer a member of staff?"); for (int ab = 0; ab < a; ab++) { System.out.println((ab+1) + " - " + n [ab][0][0]); } int ac = input.nextInt(); System.out.println("Who would you like to transfer?"); for (int ad = 1; ad < (int)n[l][0][2]; ad++) { System.out.println(ad + " - " + n[l][ad][1] + " " + n [l][ad][2]); } int ae = 0; ae = input.nextInt(); if (ae == 1 && n[ac][1][3] == "hired") { System.out.println("The branch you would like to transfer to already has a manager. Would you like to:"); System.out.println("1 - Swap both managers"); System.out.println("2 - Transfer the manager as an employee"); int al = input.nextInt(); int af = 0;
if (al == 1) { for (int aa = 0; aa < 4; aa++) { temp [aa] = n[l][1][aa]; n[l][1][aa] = n[ac-1][ae][aa]; n[ac-1][ae][aa] = temp [aa]; } } else { while (n[ac-1][af][3] == "hired" || n[ac-1][af][3] == "fired") { af++; } for (int ag = 0; ag < 4; ag++) { temp [ag] = n[l][1][ag]; n[l][1][ag] = n[ac-1][af][ag]; n[ac-1][af][ag] = temp [ag]; }
} } break; case 4: System.out.println("Please select the member of staff you would like to fire.");
for (int az = 1; az-1 <= (int)n[l][0][2]; az++) { System.out.println(az + " - " + n[l][az][0] + " " + n [l][az][1]); } int ay = input.nextInt(); if (n [l][ay][3] == "fired") { System.out.println("This employee has already been fired."); } System.out.println(n[l][ay][0] + " " + n [l][ay][1] + " is now fired."); n[l][ay][3] = "fired"; break; } zaza = 0; while (zaza == 0) { zaza++; System.out.println("Would you like to perform another action?"); System.out.println("1 - Yes"); System.out.println("2 - No"); zaza = input.nextInt(); if (i != 1 && i != 2) { System.out.println("The user input is invalid. Please try again"); zaza = 0; } } } System.out.println("Here is a list of all your employees, branches, and managers"); for (int zzz = 0; zzz < a; zzz++) { System.out.print("Branch " + (zzz+1) + ") " + n[zzz][0][0]); System.out.println(" - ID: " + n[zzz][0][1]); System.out.println(); System.out.println("Manager: " + n[zzz][1][0] + " " + n[zzz][1][1] + " - " + n[zzz][1][2] + " -- " + n[zzz][1][3]); System.out.println("Employees:"); for (int hg = 2; (hg-1) <= (int)n[zzz][0][2]; hg++) { System.out.println(n[zzz][hg][0] + " " + n[zzz][hg][1] + " - " + n[zzz][hg][2] + " -- " + n[zzz][hg][3]); } } }
public static class branch { String v; int t; public branch() { v = ""; } public branch(String info, int x) { v = info; t = x; }
public String getloc() { return v; } public int getLocID() { return t; } public int setDay1(int a) { t = t+a; return t; } public int setDay2(int a) { t = t - a; return t; } } public static class employee { String v; int t; public employee() { v = ""; } public employee(String info, int x) { v = info; t = x; }
public String getStatus() { return v; } public int getID() { return t; } public int setadd(int a) { t = a+1; return t; } public int setremove(int a) { t = a-1; return t; } } public static class manager { String v; int t; public manager() { v = ""; } public manager(String info, int x) { v = info; t = x; }
public String getManame() { return v; } public int getManID() { return t; } public int setDay1(int a) { t = t+a; return t; } public int setDay2(int a) { t = t - a; return t; } }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started