hannahaddad 15

Hi JamesCherrill

I was just trying to make it more clear to the poster. But you are certainly on right. It's like giving a fish instead of teach how to fishing. I will be careful for the next time.
regards.

hannahaddad 15

String a=new String("SMS Message");

this line means that you reserved a memory pointed by a and has the value "SMS Message". So when you say if(a==b), you are comparing the addres of the memory (like JamesCherrill said). But what you want to do is to compare the value of this memory so you use the "equals" method

a.equals(b);

hope this help.

hannahaddad 15

First you cannot define method in the static void main() method, so method1 and method2 should be in the class Salry but not into main.
Second method1 and method2 should return an interger which you didn't in your exemple, so you need to add a return statement or to change the methods so it returns nothing (from int to void)
Third the try catch exception isnt important because the method1 doesnt throw exception, so no need for try catch.

so the code should be like this, i hope this help.

public class Salary implements Interface1
{
    float pf,hra,sa,da,tax,net;

    public Salary(int sa)
    {
        this.sa = sa;
    }

    public void method1()
    {
        System.out.println("salary="+sa);

        if(sa>250000)
        {
            pf=sa*5/100;    
            hra=sa*10/100;
            da=sa*8/100;
            tax=sa*10/100;
            net=sa+tax;
            System.out.println("Net salary of an employee"+net);
        }
    }

    public void method2()
    {
        System.out.println("salary="+sa);
        if(sa>500000)
        {
            pf=sa*5/100;
            hra=sa*10/100;
            da=sa*8/100;
            tax=sa*20/100;
            net=sa+tax;
            System.out.println("Net salary of an employee"+net);
        }
        else
        {
            System.out.println("No deduction");
        }
    }

    public static void main(String args[])
    {
        int sa = Integer.parseInt(args[0]); 
        Salary s=new Salary(sa);
        s.method1();
        s.method2();
    }
}