I have been racking my brain trying to understand this fundamental concept and It is tearing me apart. Here is what I am supposed to do for my assignment:
Modify the Payroll Program so that it uses a class to store and retrieve the department’s name, the number of employees for the department, and the average salary per employee in the department. Use a constructor to initialize the department information, and a method within that class to calculate the total department salary amount (number of employees in the department times the average salary per employee). Once stop is entered as the department name, the application should terminate. Make sure the program maintains all the functionality required in previous assignments and your source code is readable and well documented. Use feedback you have received from the instructor to make any needed modifications.
Here is my code:
// Thomas Harrald IT215 // Checkpoint Payroll Program Three //Use a Class to Store and Retrieve Dept Name, Number of Employee, avg salary //Use a Constructor to Initialize the Department information, and a method within in that class // to calculate the total Department Salary Amount import java.util.Scanner; //Import Scanner public class PayrollProgramthree { public static void main( String[] args ) { Scanner input = new Scanner (System.in); String IName="null"; int INumber; float ISalary; System.out.println( "Welcome to the Payroll Program" ); while (!PayrollClass.PName.toLowerCase().equals("stop")) { System.out.println( "Please input the name of the department, type stop to end." ); IName = input.next(); PayrollClass.setName ( IName); if(PayrollClass.PName.toLowerCase().equals( "stop")) { break; } System.out.println( "Please input the number of employees" ); INumber = input.nextInt(); while (INumber < 0 ) { System.out.println ( "Please input a positive number"); INumber = input.nextInt(); } PayrollClass.setNumber ( INumber); System.out.println( "Please input the average employee salary" ); ISalary = input.nextFloat(); while ( ISalary < 0 ) { System.out.println ( " Please input a positive number"); ISalary = input.nextFloat(); } PayrollClass.setAvg ( ISalary); PayrollClass.setTotal (); System.out.printf( "The name of the department is %s\n ", PayrollClass.PName ); System.out.printf( "The total payroll is $ %s USD ", PayrollClass.totalDept); } System.out.println( "Thank you for using the Payroll Program!"); } } public class PayrollClass { private String deptName; private int numberEmployees; private float avgSalary; float totalDept; public void setName ( String PName ) { deptName = PName; } public String getName () { return deptName; } public void setNumber (int PNumber) { numberEmployees = PNumber; } public int getNumber() { return numberEmployees; } public void setAvg (float PSalary) { avgSalary = PSalary; } public float getAvg () { return avgSalary; } public float setTotal () { totalDept = PNumber * PSalary; } }
Any help would be appreciated! Thank you kindly!