Originally Posted by
jps
//**could use a comment to describe the purpose and use of this class as a whole
{
private String name;
private int numberEmployees;
private float avgSalary;
String className;//**what does this variable do?
int classNumber;//**what does this variable do?
float classSalary;//**what does this variable do?
public PayrollClass(String className, int classNumber, float classSalary)
{
name = className;
numberEmployees = classNumber;
avgSalary = classSalary;
}
public String getName() // get method for retreiving the department name
{
return name;
}
public int getNumber() // get method for retrieving the number of employees
{
return numberEmployees;
}
public float getAvg() //get method for retreiving average salary
{
return avgSalary;
}
public float getTotal() //method for multiplying the number of employees times the avg salary
{
return avgSalary * numberEmployees;
}
}
//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 PayrollProgramPartThree // Main class that will store and retreive the information required by assignment
{
public static void main( String[] args )
{
Scanner input = new Scanner (System.in);
String deptName = "null";
int numberofEmployees;
float Salary;
float totalofDept;//**what does this variable do?
System.out.println( "Welcome to the Payroll Program" );
while (!deptName.toLowerCase().equals("stop")) //while loop to ask for information repeatedly until "stop" is typed
//**I still don't think all of this is necessary. Try while(true)
{
System.out.println( "Please input the name of the department type stop to end." ); //get name of dept
deptName = input.next();
if(deptName.toLowerCase().equals( "stop")) //breaks the while loop
{
break;
}
System.out.println( "Please input the number of employees" );
numberofEmployees = input.nextInt();
while (numberofEmployees < 0 ) //validates user input
{
System.out.println ( "Please input a positive number");
numberofEmployees = input.nextInt();
}
System.out.println( "Please input the average employee salary" );
Salary = input.nextFloat();
while ( Salary < 0 ) // validates user input
{
System.out.println ( " Please input a positive number");
Salary = input.nextFloat();
}
PayrollClass myPayrollClass = new PayrollClass( deptName, numberofEmployees, Salary); //constructor to initialize an object with the information inputted above
System.out.printf( "The name of the department is %s\n ", myPayrollClass.getName() );
System.out.printf( "The total payroll is $%sUSD ", myPayrollClass.getTotal()); //method to get the total
}
System.out.println( "Thank you for using the Payroll Program!");
}
}
I think one more go over would just about cover it. There are some variables here and there that I am not sure you need. A few places I personally would like to see a comment. Still not quite up to java par with the format. I was someone who refused to use java convention for a long time. Over time I have found looking at java code with java format keeps the brain on java easier than seeing old styles used in old languages.
Well now that the assignment is turned and finish, I can work on cleaning up the code and fixing some things you pointed out that wasn't related directly to the assignment. I am going to start the code from scratch and no reference to the original, just so I know I got a hold on it. I'll post the finished code here when I'm done.