SHOWS ERROR: /SalaryPaycheck.java:1: error: class, interface, or enum expected S
ID: 3702980 • Letter: S
Question
SHOWS ERROR:
/SalaryPaycheck.java:1: error: class, interface, or enum expected
SalaryPaycheck.java()
^
1 error
SalaryPaycheck.java
import java.util.Scanner;
public class SalaryPaycheck {
private float grossAmount;
private int employeeId;
private int maritalStatus;
private String employeeName;
// getter and setter
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public float getGrossAmount() {
return grossAmount;
}
public void setGrossAmount(float grossAmount) {
this.grossAmount = grossAmount;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public int getMaritalStatus() {
return maritalStatus;
}
public void setMaritalStatus(int maritalStatus) {
this.maritalStatus = maritalStatus;
}
// method to calculate NetPay
public void calculateNetPay(float grossAmount,int employeeID,int maritialStatus)
{
float federalIncomeTax = 0;
//it is for single person
if (getMaritalStatus() ==0)
{
// this is for salary less than $2000
if(getGrossAmount()<=2000)
{
federalIncomeTax = (getGrossAmount() * 10)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary less than $5000 here is some trick as for 2000 we pay 200 tax so added that tax and deducted 2000
//gross salary as this is the way to calculate fedral tax
else if(getGrossAmount()<=5000)
{
federalIncomeTax = 200 + ((getGrossAmount()-2000) * 20)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary more than $5000 here for 5000 we pay 2000 + 3000 thus tax are 10% of 2000-> 200 and
//20% of 3000 -> 600 all total 200+600 =800 ,added this in tax and removed 5000 from gross salary
else if(getGrossAmount()>5000)
{
federalIncomeTax = 800 + ((getGrossAmount()-5000) * 30)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
}
// For married person
else
{
//Same operation as done for single
// this is for salary less than $4000
if(getGrossAmount()<=4000)
{
federalIncomeTax = (getGrossAmount() * 10)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary less than $7000
else if(getGrossAmount()<=7000)
{
federalIncomeTax = 400 + ((getGrossAmount()-4000) * 20)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary more than $7000
else if(getGrossAmount()>7000)
{
federalIncomeTax = 100 + ((getGrossAmount()-7000) * 30)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
}
// 3.5 after removing federal income tax
float stateTax = ((getGrossAmount()-federalIncomeTax) * 3.5f)/100;
System.out.println("State Tax:" +stateTax);
//5 % on gross salary
float retirementPlan = (getGrossAmount() * 5)/100;
System.out.println("Retirement Plan:" +retirementPlan);
//6.5% on gross salary
float healthInsurance =(getGrossAmount() * 6.5f)/100;
System.out.println("Health Insurance:" +healthInsurance);
// net Pay after removing all taxes
float netSalary = getGrossAmount() - federalIncomeTax - stateTax - healthInsurance - retirementPlan;
System.out.println("Net Salary:" +netSalary);
}
public static void main(String[] args) {
//user input and function call
SalaryPaycheck spcheck = new SalaryPaycheck();
Scanner sc = new Scanner(System.in);
System.out.println("Enter employee ID");
spcheck.setEmployeeId(sc.nextInt());
System.out.println("Enter employee name");
spcheck.setEmployeeName(sc.next());
System.out.println("Enter employee maritialstatus 0 for single 1 for married");
spcheck.setMaritalStatus(sc.nextInt());
System.out.println("Enter employee GrossSalary");
spcheck.setGrossAmount(sc.nextFloat());
System.out.println("Employee ID :" +spcheck.getEmployeeId());
System.out.println("Gross Amount: $" +spcheck.getGrossAmount());
spcheck.calculateNetPay(spcheck.getGrossAmount(), spcheck.employeeId, spcheck.getMaritalStatus());
}
}
Explanation / Answer
Hi
I do not see any issue with your code. it is working fine as expected. Please save the code with the file name "SalaryPaycheck.java" then open cmd prompt and go to the path where this file has been saved.
then
c:/>javac SalaryPaycheck.java
c:/> java SalaryPaycheck
SalaryPaycheck.java
import java.util.Scanner;
public class SalaryPaycheck {
private float grossAmount;
private int employeeId;
private int maritalStatus;
private String employeeName;
// getter and setter
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public float getGrossAmount() {
return grossAmount;
}
public void setGrossAmount(float grossAmount) {
this.grossAmount = grossAmount;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public int getMaritalStatus() {
return maritalStatus;
}
public void setMaritalStatus(int maritalStatus) {
this.maritalStatus = maritalStatus;
}
// method to calculate NetPay
public void calculateNetPay(float grossAmount,int employeeID,int maritialStatus)
{
float federalIncomeTax = 0;
//it is for single person
if (getMaritalStatus() ==0)
{
// this is for salary less than $2000
if(getGrossAmount()<=2000)
{
federalIncomeTax = (getGrossAmount() * 10)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary less than $5000 here is some trick as for 2000 we pay 200 tax so added that tax and deducted 2000
//gross salary as this is the way to calculate fedral tax
else if(getGrossAmount()<=5000)
{
federalIncomeTax = 200 + ((getGrossAmount()-2000) * 20)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary more than $5000 here for 5000 we pay 2000 + 3000 thus tax are 10% of 2000-> 200 and
//20% of 3000 -> 600 all total 200+600 =800 ,added this in tax and removed 5000 from gross salary
else if(getGrossAmount()>5000)
{
federalIncomeTax = 800 + ((getGrossAmount()-5000) * 30)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
}
// For married person
else
{
//Same operation as done for single
// this is for salary less than $4000
if(getGrossAmount()<=4000)
{
federalIncomeTax = (getGrossAmount() * 10)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary less than $7000
else if(getGrossAmount()<=7000)
{
federalIncomeTax = 400 + ((getGrossAmount()-4000) * 20)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
// this is for salary more than $7000
else if(getGrossAmount()>7000)
{
federalIncomeTax = 100 + ((getGrossAmount()-7000) * 30)/100;
System.out.println("Federal Income Tax:" +federalIncomeTax);
}
}
// 3.5 after removing federal income tax
float stateTax = ((getGrossAmount()-federalIncomeTax) * 3.5f)/100;
System.out.println("State Tax:" +stateTax);
//5 % on gross salary
float retirementPlan = (getGrossAmount() * 5)/100;
System.out.println("Retirement Plan:" +retirementPlan);
//6.5% on gross salary
float healthInsurance =(getGrossAmount() * 6.5f)/100;
System.out.println("Health Insurance:" +healthInsurance);
// net Pay after removing all taxes
float netSalary = getGrossAmount() - federalIncomeTax - stateTax - healthInsurance - retirementPlan;
System.out.println("Net Salary:" +netSalary);
}
public static void main(String[] args) {
//user input and function call
SalaryPaycheck spcheck = new SalaryPaycheck();
Scanner sc = new Scanner(System.in);
System.out.println("Enter employee ID");
spcheck.setEmployeeId(sc.nextInt());
System.out.println("Enter employee name");
spcheck.setEmployeeName(sc.next());
System.out.println("Enter employee maritialstatus 0 for single 1 for married");
spcheck.setMaritalStatus(sc.nextInt());
System.out.println("Enter employee GrossSalary");
spcheck.setGrossAmount(sc.nextFloat());
System.out.println("Employee ID :" +spcheck.getEmployeeId());
System.out.println("Gross Amount: $" +spcheck.getGrossAmount());
spcheck.calculateNetPay(spcheck.getGrossAmount(), spcheck.employeeId, spcheck.getMaritalStatus());
}
}
Output:
Enter employee ID
12345
Enter employee name
Sekhar
Enter employee maritialstatus 0 for single 1 for married
1
Enter employee GrossSalary
20000
Employee ID :12345
Gross Amount: $20000.0
Federal Income Tax:4000.0
State Tax:560.0
Retirement Plan:1000.0
Health Insurance:1300.0
Net Salary:13140.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.