Karla News

Java Programming (IT 215) – Payroll Program

This program is a great example of how to get a constructor to pass 411 and return it after the calculations. I hope it helps others out as it was a real pain to get working.

PAYROLL . JAVA

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

// @author Luther Mann

// IT 215

// 12-13=10

// Payroll 1

package payroll;

/**

*

*

*/

import java.util.Scanner;

public class Payroll {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner input = new Scanner(System.in); //accepts keyboard input

Employees sa; //storage object

String FirstName; // Decalre First Name as String

String LastName; // Declare Last Name as String

double PayRate; //Declare ParRate as double

double Hours; // Declare Hours as String

double Pay; //Declares Pay as Double

Boolean Continue = true; // Does FirstName = Stop

while(Continue=true)

{

Hours = 0;

PayRate = 0;

System.out.println(“Employees First Name: “);

System.out.println(“Type Stop to end program”);

FirstName= input.next(); // Input Empoyee’s First Name

if(!FirstName.equalsIgnoreCase(“stop”)){

System.out.println(“Employees Last Name: “);

LastName = input.next(); // Input Employee’s Last Name

while(PayRate<=0)

{

System.out.println(“Employees Hourly Rate: “);

PayRate = input.nextDouble(); // Input Employee’s Hourly Rate

}

while(Hours<=0)

{

System.out.println(“Employees Total Work Hours: “);

Hours = input.nextDouble(); // Input Employee’s Total Hours Worked

}

//Create a new class and pass the values of the variables

sa = new Employees(FirstName, LastName, PayRate, Hours);

// Display Employee’s First and Last name and Current Pay

System.out.printf(“%s %s’s Current Pay: $%.2fn”, sa.getFrstName(), sa.getLstName(), sa.EmployeePay());

System.out.println(” “);

}

else

break;

}

}

}

EMPLOYEES . JAVA

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

See also  How to Get Those Telemarketers to Stop Calling You!

*/

package payroll;

/**

*

* @author Luther Mann

*/

public class Employees {

//Define class Variables

String FrstName; // Decalre First Name as String

String LstName; // Declare Last Name as String

double GrossPay; // Declare GrossPay as Double

double PyRate; // Declare PayRate as Double

double Hors; // Declare Hours as Double

double Overtime; // Declare Overtime as Double

double OTPay; // Declare OTPay as Double

double EmpPay; //Declare Pay as Double

Employees(String FirstName, String LastName, double PayRate, double Hours)

{

this.FrstName = FirstName;

this.LstName = LastName;

this.Hors = Hours;

this.PyRate = PayRate;

}

/**

*

* @return the FrstNAme

*/

public String getFrstName(){

return FrstName;

}

/**

*

* @param FrstName the FrstName to set

*/

public void setFrstName(String FrstName){

this.FrstName = FrstName;

}

/**

*

* @return the LstNAme

*/

public String getLstName() {

return LstName;

}

/**

*

* @param LstName the LstName to set

*/

public void setLstName(String LstName) {

this.LstName = LstName;

}

/**

*

* @return the Hors

*/

public Double getHors () {

return Hors;

}

/**

*

* @param Hors the Hors to set

*/

public void setHors (Double Hors) {

this.Hors = Hors;

}

/**

*

* @return the PyRate

*/

public Double getPyRate () {

return PyRate;

}

/**

* @param PyRate the PyRate to set

*/

public void setPyRate (double PyRate) {

this.PyRate = PyRate;

}

public double EmployeePay() //Compute employee Pay and return it

{

if (Hors > 40) {

Overtime = (Hors – 40);

GrossPay = (PyRate * 40);

OTPay = (Overtime*(PyRate*1.5));

EmpPay = (OTPay + GrossPay);

}

else {

EmpPay=(PyRate*40);

}

return EmpPay;

}

}