Here's my assignment question:
**Develop a Payroll class that consists of two user-defined methods, namely calculateNetPay() and printOutput() methods. The calculateNetPay() method is used to calculate the employee's net pay, as the formula follows:
Net pay = gross pay - state tax and federal tax
In the same class, print the net pay value in the printOutput() method.
Then, develop a PayrollDemo class which consists of the main method. Inside the main method, prompt a user to insert employer ID, gross pay, state tax, and federal tax. Create an object to invoke calculateNetPay() and printOutput() methods. Your program should produce the following output:
Enter your employee ID number: 2150
Enter your gross pay: $ 4000
Enter your State Tax: $ 300
Enter your Federal Tax: $500Net pay is: $3200.0**
So, here's MY trial of coding for the Payroll class:
public class Payroll
{
public double grossPay;
public double stateTax;
public double federalTax;
public double calculateNetPay()
{
return grossPay - (stateTax + federalTax);
}
public double printOutput()
{
System.out.println(" Net Pay is: " + y02);
}
}
but with one error here:
Payroll.java:14: error: cannot find symbol
System.out.println(" Net Pay is: " + y02);
^
symbol: variable y02
location: class Payroll
1 error
AND here's MY trial coding for the PayrollDemo class:
import java.util.Scanner;
public class PayrollDemo
{
public static void main(String[] args)
{
int employeeID, grossPay, stateTax, federalTax;
double y01, y02;
Scanner keyboard = new Scanner(System.in);
System.out.println(" Enter your employee ID number: ");
employeeID = keyboard.nextInt();
System.out.println(" Enter your Gross pay: ");
grossPay = keyboard.nextInt();
System.out.println(" Enter your State Tax: ");
stateTax = keyboard.nextInt();
System.out.println(" Enter your Federal Tax: ");
federalTax = keyboard.nextInt();
Payroll taxes = new Payroll();
y01 = taxes.calculateNetPay();
y02 = taxes.printOutput();
}
}
And the error that occured when I tried compiling this PayrollDemo class is the same with the error I got for the Payroll class.
So, It'd be great if someone could shed some light on this matter, thanks in advance!