207k views
4 votes
Assignment Directions

Use the NetBeans IDE, create a Java program to declare and initialize variables to compute the tax amount, gross pay, and net pay for three employees. Use arithmetic operators to achieve these results, and display the variable names and their contents both before computations and afterward.


Assignment Guidelines

Use this skeleton code as a model for your project:


Java Skeleton Code

/* ************************************************************************


*


* YourName DLM: 1/1/12 DescriptiveFileName. Java


*


*Description: these are the basic required components of a simple Java program


* this program prints Skeleton code to the screen as a string literal


* declares and initializes three variables, manipulates the data values


* within those variables by using arithmetic operators to change the


* Values held by the variables, and prints the contents of the variables to


* the screen/output box


* Lesson 8


************************************************************************


*/


public class example2 {


public static void main(String[] someVariableName) {

float hrsWorked = 40;

double payRate = 10. 00;

double taxRate1 = 0. 25;

double taxRate2 = 0. 50;

double grossPay = 0. 00;

double taxAmt = 0. 00;

Double netPay = 0. 00;


System. Out. Println("hrsWorked = " + hrsWorked); // prints the variable

//name,

System. Out. Println("payRate = $" + payRate); // the equal sign, and the

System. Out. Println("taxRate1 = " + taxRate1); // and the value stored in it

System. Out. Println("taxRate2 = " + taxRate2);

System. Out. Println("grossPay =$" + grossPay);

System. Out. Println("taxAmt = $" + taxAmt);

System. Out. Println("netPay = $" + netPay);


//

// use arithmetic operators to turn data into information

//

grossPay = payRate * hrsWorked; // puts the results from the

boolean bigGrossPay = (grossPay >= 500);

taxAmt = grossPay * taxRate1; // right-hand side of the equal sign

boolean littleGrossPay = grossPay <= 500; // into the variable on the left-hand

taxAmt = grossPay * taxRate2; // side of it

netPay = grossPay - taxAmt;


System. Out. Println("hrsWorked = " + hrsWorked); //prints new values

System. Out. Println("payRate = $" + payRate);

System. Out. Println("taxRate1 = " + taxRate1);

System. Out. Println("taxRate2 = " + taxRate2);

System. Out. Println("grossPay =$" + grossPay);

System. Out. Println("taxAmt = $" + taxAmt);

System. Out. Println("netPay = $" + netPay);


System. Out. Println("Skeleton code");

}

}


You may copy the code into the IDE and modify the code for your project, or type in new code. Create the appropriate number of variables with appropriate data types for hours worked, pay rate, tax amount, gross pay, and net pay. Display the results. Document your code

User Gabbyboy
by
9.0k points

1 Answer

4 votes

Answer:

public class EmployeePayroll {

public static void main(String[] args) {

// Employee 1

int emp1Hours = 40;

double emp1PayRate = 20.00;

double emp1TaxRate = 0.25;

double emp1GrossPay = emp1Hours * emp1PayRate;

double emp1TaxAmt = emp1GrossPay * emp1TaxRate;

double emp1NetPay = emp1GrossPay - emp1TaxAmt;

// Employee 2

int emp2Hours = 35;

double emp2PayRate = 15.00;

double emp2TaxRate = 0.20;

double emp2GrossPay = emp2Hours * emp2PayRate;

double emp2TaxAmt = emp2GrossPay * emp2TaxRate;

double emp2NetPay = emp2GrossPay - emp2TaxAmt;

// Employee 3

int emp3Hours = 45;

double emp3PayRate = 25.00;

double emp3TaxRate = 0.30;

double emp3GrossPay = emp3Hours * emp3PayRate;

double emp3TaxAmt = emp3GrossPay * emp3TaxRate;

double emp3NetPay = emp3GrossPay - emp3TaxAmt;

// Display results for Employee 1

System.out.println("Employee 1:");

System.out.println("Hours worked: " + emp1Hours);

System.out.println("Pay rate: $" + emp1PayRate);

System.out.println("Gross pay: $" + emp1GrossPay);

System.out.println("Tax rate: " + emp1TaxRate);

System.out.println("Tax amount: $" + emp1TaxAmt);

System.out.println("Net pay: $" + emp1NetPay);

// Display results for Employee 2

System.out.println("\\Employee 2:");

System.out.println("Hours worked: " + emp2Hours);

System.out.println("Pay rate: $" + emp2PayRate);

System.out.println("Gross pay: $" + emp2GrossPay);

System.out.println("Tax rate: " + emp2TaxRate);

System.out.println("Tax amount: $" + emp2TaxAmt);

System.out.println("Net pay: $" + emp2NetPay);

// Display results for Employee 3

System.out.println("\\Employee 3:");

System.out.println("Hours worked: " + emp3Hours);

System.out.println("Pay rate: $" + emp3PayRate);

System.out.println("Gross pay: $" + emp3GrossPay);

System.out.println("Tax rate: " + emp3TaxRate);

System.out.println("Tax amount: $" + emp3TaxAmt);

System.out.println("Net pay: $" + emp3NetPay);

}

}

Step-by-step explanation:

In this program, we declare and initialize variables for the hours worked, pay rate, tax rate, gross pay, and net pay for three employees. We use arithmetic operators to compute the values for gross pay, tax amount, and net pay. We then display the results for each employee using System.out.println().

User Dougkramer
by
7.8k points