0% found this document useful (0 votes)
12 views3 pages

Lab4 (Java)

Uploaded by

Kithinji Geofrey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Lab4 (Java)

Uploaded by

Kithinji Geofrey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lab4

Create a new project lab4 in any IDE that you use.


You will need two java files in one folder to run the program successfully.

These files are;

1. [Link]
2. [Link]

You have to run the program from the [Link] since this is
where the main method for the program is (entry to the program).

Below is the code for the programs

[Link]

package lab4;

public class Employee {

private String firstName;

private String lastName;

private double hourlyRate;

private double numberOfHoursWorked;

public Employee(String firstName, String lastName, double hourlyRate,


double numberOfHoursWorked) {

[Link] = firstName;

[Link] = lastName;

[Link] = hourlyRate;

[Link] = numberOfHoursWorked < 40 ? 40 :


numberOfHoursWorked;

}
public double computeGrossSalary() {

return numberOfHoursWorked * hourlyRate;

public double computeTaxRate(double grossSalary) {

return grossSalary <= 1000 ? 0.015 : 0.0161;

public double computeNetSalary() {

double grossSalary = computeGrossSalary();

double taxRate = computeTaxRate(grossSalary);

return grossSalary - (grossSalary * taxRate);

public void displayNetSalary() {

double grossSalary = computeGrossSalary();

double netSalary = computeNetSalary();

[Link]("Employee: %s %s%n", firstName, lastName);

[Link]("Hours Worked: %.2f%n", numberOfHoursWorked);

[Link]("Hourly Rate: $%.2f%n", hourlyRate);

[Link]("Gross Salary: $%.2f%n", grossSalary);

[Link]("Net Salary: $%.2f%n", netSalary);

[Link]("----------------------------------------");

[Link]

package lab4;
import [Link];

public class EmployeeTester {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter employee first name: ");

String firstName = [Link]();

[Link]("Enter employee last name: ");

String lastName = [Link]();

[Link]("Enter number of hours worked: ");

double hoursWorked = [Link]();

[Link]("Enter hourly rate: ");

double hourlyRate = [Link]();

Employee employee = new Employee(firstName, lastName, hourlyRate,


hoursWorked);

[Link]();

[Link]();

You might also like