Output error

waltbaby315
waltbaby315 used Ask the Experts™
on
Can someone help me figure out this error?

class Employee1
{
    private int age;
    private int id;
    private int salary;
   
    private String name;
    private String position;
   
    public Employee1(String name, int id, int salary, int age, String position)
    {
        this.name = name;
        this.id = id;
        this.salary = salary;
        this.age = age;
        this.position = position;
    }
   
    public int getFedTax()
    {
        return (int)((salary-800)*0.17);
    }
   
    public int getSsTax(int rate)
    {
         
        return (int)((rate/100)/salary);
         
    }
   
    public int getHealthFee(int rate)
    {
         
        return (int)((rate/100)/salary);
         
    }
   
    public int getInsurance()
    {
       
        if (salary<40)
            return (int)(salary*0.03);
        if (salary<50)
            return (int)(salary*0.04);
        if (salary<60)
            return (int)(salary*0.05);
        else
            return (int)(salary*0.06);
    }
   
    public double getNetPay()
    {
         
        return salary-getFedTax()-getSsTax(1)-getHealthFee(3)-getInsurance();
    }
}


class Employee1
{
    public static void main (String [] args)
    {
        Employee Fred = new Employee("Freddy", 1, 1000000, 22, "Garbage sanitisor");
        Employee Sarah = new Employee("Sarah", 1, 500000, 46, "<<Insert humorous profession name>>");
        System.out.println("Fred's Fex tax is: " + Fred.getFedTax());
        System.out.println("Fred's SS tax (rate of 1%) is: " + Fred.getSsTax(1));
        System.out.println("Fred's Health fee (rate of 3%) is: " + Fred.getHealthFee(3));
        System.out.println("Fred's insurance cost is: " + Fred.getInsurance());
        System.out.println("Fred's net pay is: " + Fred.getNetPay());
        System.out.println("---------------------------");
        System.out.println("Sarah's Fex tax is: " + Sarah.getFedTax());
        System.out.println("Sarah's SS tax (rate of 1%) is: " + Sarah.getSsTax(1));
        System.out.println("Sarah's Health fee (rate of 3%) is: " + Sarah.getHealthFee(3));
        System.out.println("Sarah's insurance cost is: " + Sarah.getInsurance());
        System.out.println("Sarah's net pay is: " + Sarah.getNetPay());
    }
}
16-May.JPG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mick BarryJava Developer
Top Expert 2010

Commented:
>       Employee Fred = new Employee("Freddy", 1, 1000000, 22, "Garbage sanitisor");
  >      Employee Sarah = new Employee("Sarah", 1, 500000, 46, "<<Insert humorous profession name>>");

change those 2 to:


        Employee1 Fred = new Employee1("Freddy", 1, 1000000, 22, "Garbage sanitisor");
        Employee1 Sarah = new Employee1("Sarah", 1, 500000, 46, "<<Insert humorous profession name>>");
Mick BarryJava Developer
Top Expert 2010

Commented:
or change your class name to Employee instead of Employee1

basically you are using the wrong classname
Awarded 2011
Awarded 2011

Commented:
You have two times "class Employee1" in your code
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Mick BarryJava Developer
Top Expert 2010

Commented:
you can also put main in the same class
Java Developer
Top Expert 2010
Commented:
save the attached as Employee.java and try that

public class Employee
{
    private int age;
    private int id;
    private int salary;
    
    private String name;
    private String position;
    
    public Employee(String name, int id, int salary, int age, String position)
    {
        this.name = name;
        this.id = id;
        this.salary = salary;
        this.age = age;
        this.position = position;
    }
    
    public int getFedTax()
    { 
        return (int)((salary-800)*0.17);
    }
    
    public int getSsTax(int rate)
    {
         
        return (int)((rate/100)/salary);
         
    }
    
    public int getHealthFee(int rate)
    {
         
        return (int)((rate/100)/salary);
         
    }
    
    public int getInsurance()
    {
        
        if (salary<40)
            return (int)(salary*0.03);
        if (salary<50)
            return (int)(salary*0.04);
        if (salary<60)
            return (int)(salary*0.05);
        else
            return (int)(salary*0.06);
    }
    
    public double getNetPay()
    {
         
        return salary-getFedTax()-getSsTax(1)-getHealthFee(3)-getInsurance();
    }
    public static void main (String [] args)
    {
        Employee Fred = new Employee("Freddy", 1, 1000000, 22, "Garbage sanitisor");
        Employee Sarah = new Employee("Sarah", 1, 500000, 46, "<<Insert humorous profession name>>");
        System.out.println("Fred's Fex tax is: " + Fred.getFedTax());
        System.out.println("Fred's SS tax (rate of 1%) is: " + Fred.getSsTax(1));
        System.out.println("Fred's Health fee (rate of 3%) is: " + Fred.getHealthFee(3));
        System.out.println("Fred's insurance cost is: " + Fred.getInsurance());
        System.out.println("Fred's net pay is: " + Fred.getNetPay());
        System.out.println("---------------------------");
        System.out.println("Sarah's Fex tax is: " + Sarah.getFedTax());
        System.out.println("Sarah's SS tax (rate of 1%) is: " + Sarah.getSsTax(1));
        System.out.println("Sarah's Health fee (rate of 3%) is: " + Sarah.getHealthFee(3));
        System.out.println("Sarah's insurance cost is: " + Sarah.getInsurance());
        System.out.println("Sarah's net pay is: " + Sarah.getNetPay());
    }
}

Open in new window

Awarded 2011
Awarded 2011

Commented:


this code compiles


public class Employee1
{
    private int age;
    private int id;
    private int salary;
    
    private String name;
    private String position;
    
    public Employee1(String name, int id, int salary, int age, String position)
    {
        this.name = name;
        this.id = id;
        this.salary = salary;
        this.age = age;
        this.position = position;
    }
    
    public int getFedTax()
    { 
        return (int)((salary-800)*0.17);
    }
    
    public int getSsTax(int rate)
    {
         
        return (int)((rate/100)/salary);
         
    }
    
    public int getHealthFee(int rate)
    {
         
        return (int)((rate/100)/salary);
         
    }
    
    public int getInsurance()
    {
        
        if (salary<40)
            return (int)(salary*0.03);
        if (salary<50)
            return (int)(salary*0.04);
        if (salary<60)
            return (int)(salary*0.05);
        else
            return (int)(salary*0.06);
    }
    
    public double getNetPay()
    {
         
        return salary-getFedTax()-getSsTax(1)-getHealthFee(3)-getInsurance();
    }




    public static void main (String [] args)
    {
        Employee1 Fred = new Employee1("Freddy", 1, 1000000, 22, "Garbage sanitisor");
        Employee1 Sarah = new Employee1("Sarah", 1, 500000, 46, "<<Insert humorous profession name>>");
        System.out.println("Fred's Fex tax is: " + Fred.getFedTax());
        System.out.println("Fred's SS tax (rate of 1%) is: " + Fred.getSsTax(1));
        System.out.println("Fred's Health fee (rate of 3%) is: " + Fred.getHealthFee(3));
        System.out.println("Fred's insurance cost is: " + Fred.getInsurance());
        System.out.println("Fred's net pay is: " + Fred.getNetPay());
        System.out.println("---------------------------");
        System.out.println("Sarah's Fex tax is: " + Sarah.getFedTax());
        System.out.println("Sarah's SS tax (rate of 1%) is: " + Sarah.getSsTax(1));
        System.out.println("Sarah's Health fee (rate of 3%) is: " + Sarah.getHealthFee(3));
        System.out.println("Sarah's insurance cost is: " + Sarah.getInsurance());
        System.out.println("Sarah's net pay is: " + Sarah.getNetPay());
    }
} 
 

Open in new window

Awarded 2011
Awarded 2011

Commented:
And successfully executes
This is the output:

Fred's Fex tax is: 169864
Fred's SS tax (rate of 1%) is: 0
Fred's Health fee (rate of 3%) is: 0
Fred's insurance cost is: 60000
Fred's net pay is: 770136.0
---------------------------
Sarah's Fex tax is: 84864
Sarah's SS tax (rate of 1%) is: 0
Sarah's Health fee (rate of 3%) is: 0
Sarah's insurance cost is: 30000
Sarah's net pay is: 385136.0

Open in new window

Awarded 2011
Awarded 2011

Commented:
Well, the numbers seem strange though
Awarded 2011
Awarded 2011

Commented:
You get zeroes in taxes as you tend to return lot of in fact double values  as int's

Awarded 2011
Awarded 2011

Commented:


Make sure you correct multiple errors in your code - related to
returning int instead of double, but not only those -
in some places you delete by salary, instead of multiplying it.

I think I corrected at least most obvious issues, and it gives some reasonable
results


public class Employee1
{
    private int age;
    private int id;
    private int salary;

    private String name;
    private String position;

    public Employee1(String name, int id, int salary, int age, String position)
    {
        this.name = name;
        this.id = id;
        this.salary = salary;
        this.age = age;
        this.position = position;
    }

    public double getFedTax()
    {
        return ((salary-800)*0.17);
    }

    public double getSsTax(int rate)
    {

        return (((double)rate)/100)*salary;

    }

    public double getHealthFee(int rate)
    {

        return (((double)rate/100))*salary;

    }

    public double getInsurance()
    {

        if (salary<40)
            return (salary*0.03);
        if (salary<50)
            return (salary*0.04);
        if (salary<60)
            return (salary*0.05);
        else
            return (salary*0.06);
    }

    public double getNetPay()
    {

        return salary-getFedTax()-getSsTax(1)-getHealthFee(3)-getInsurance();
    }




    public static void main (String [] args)
    {
        Employee1 Fred = new Employee1("Freddy", 1, 1000000, 22, "Garbage sanitisor");
        Employee1 Sarah = new Employee1("Sarah", 1, 500000, 46, "<<Insert humorous profession name>>");
        System.out.println("Fred's Fex tax is: " + Fred.getFedTax());
        System.out.println("Fred's SS tax (rate of 1%) is: " + Fred.getSsTax(1));
        System.out.println("Fred's Health fee (rate of 3%) is: " + Fred.getHealthFee(3));
        System.out.println("Fred's insurance cost is: " + Fred.getInsurance());
        System.out.println("Fred's net pay is: " + Fred.getNetPay());
        System.out.println("---------------------------");
        System.out.println("Sarah's Fex tax is: " + Sarah.getFedTax());
        System.out.println("Sarah's SS tax (rate of 1%) is: " + Sarah.getSsTax(1));
        System.out.println("Sarah's Health fee (rate of 3%) is: " + Sarah.getHealthFee(3));
        System.out.println("Sarah's insurance cost is: " + Sarah.getInsurance());
        System.out.println("Sarah's net pay is: " + Sarah.getNetPay());
    }
}

Open in new window


Fred's Fex tax is: 169864.0
Fred's SS tax (rate of 1%) is: 10000.0
Fred's Health fee (rate of 3%) is: 30000.0
Fred's insurance cost is: 60000.0
Fred's net pay is: 730136.0
---------------------------
Sarah's Fex tax is: 84864.0
Sarah's SS tax (rate of 1%) is: 5000.0
Sarah's Health fee (rate of 3%) is: 15000.0
Sarah's insurance cost is: 30000.0
Sarah's net pay is: 365136.0

Open in new window

> class Employee1

You are referring to wrong class "Employee1", you should be looking at
definition of "Employee" class

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial