Question
Say we have a personnel directory management system that holds the following java files: --------------------------------------------------------------------------------------------------------- Employee.java: public class Employee extends Person{ private int empID; private
Say we have a personnel directory management system that holds the following java files:
---------------------------------------------------------------------------------------------------------
Employee.java:
public class Employee extends Person{ private int empID; private double baseSalary; public Employee(String last, String first, String middle, int id, double sal) { super(last, first, middle); empID = id; baseSalary = sal;
}
public int getID() { return empID;
}
}
---------------------------------------------------------------------------------------------------------
Person.java
public class Person { public String last; public String first; public String middle;
public Person(String last, String first, String middle) { this.last = last; this.first = first; this.middle = middle;
}
public void printName(int order) {
if(order == 0) { System.out.println(first + " " + middle + " " + last);
}else if(order == 1) {
System.out.println(last + " ," + middle + " " + first);
} else if(order == 2) {
System.out.println(last + " ," + first + " " + middle);
} } }
---------------------------------------------------------------------------------------------------------
Personnel.java
import java.util.*; public class Personnel {
public ArrayList
public Personnel() { personList = new ArrayList
public void addPersonnel(Person p) { personList.add(p); } }
---------------------------------------------------------------------------------------------------------
PersonnelDirectory.java
import java.util.Scanner; public class PersonnelDirectory {
public static void main(String[] args) { Personnel per = new Personnel(); totalObjects total = new totalObjects(); Scanner scan = new Scanner(System.in); String firstN, lastN, middleN; int empID; double salary; int choice = -1;
do{
System.out.println("Welcome to the Personnel Directory Management System"); System.out.println("====================================================");
System.out.println(" \t 1. Add Personel"); System.out.println(" \t 2. Find Personel"); System.out.println(" \t 3. Print Names"); System.out.println(" \t 4. Number of Entries in the Directory");
System.out.println(" \t Select one of the options above (1, 2, 3, 4)"); choice = scan.nextInt(); scan.nextLine();
switch(choice) { case 1: System.out.println("Enter first name: "); firstN = scan.nextLine(); System.out.println("Enter last name: "); lastN = scan.nextLine(); System.out.println("Enter middle name: "); middleN = scan.nextLine();
System.out.println("Enter empploy id : "); empID = scan.nextInt(); System.out.println("Enter base salaey" ); salary = scan.nextDouble(); scan.nextLine();
Employee e1 = new Employee(lastN, firstN, middleN, empID, salary);
per.addPersonnel(e1); total.objectAdded();
break;
case 2:
System.out.println("Enter firts name : "); firstN = scan.nextLine();
System.out.println("Enter last name : "); lastN = scan.nextLine();
boolean found = false; int loc =-1; for(int i =0; i if(found) { System.out.println("Found"); per.personList.get(loc).printName(0); }else { System.out.println("not found"); Person p1 = new Person(lastN, firstN, " "); per.personList.add(p1); total.objectAdded(); } break; case 3: System.out.println("Enter the order 0: first, middle, last, 1: first, last, middle, 2: last, first , middle "); int order = scan.nextInt(); for(int i=0; i per.personList.get(i).printName(order); } break; case 4: System.out.println("Total Entries : " + total.getTotalObjects()); break; } } while(true); } } --------------------------------------------------------------------------------------------------------- totalObjects.java public class totalObjects { private static int numObjects = 0; public totalObjects() { numObjects=0; } public void objectAdded() { numObjects++; } public int getTotalObjects() { return numObjects; } } --------------------------------------------------------------------------------------------------------- Can you modify the following code that fixes all OOC violations and Coupling? Seriously Thank you.
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