Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I want to calculate tax from salary
public float getVasikosMisthos() {
      return vasikosMisthos;
  }
  public void setVasikosMisthos(float vasikosMisthos) throws  NegativeSalaryException  {
      if(vasikosMisthos<=0){
         throw new  NegativeSalaryException(vasikosMisthos);
      }
          this.vasikosMisthos = vasikosMisthos;
  }


public double taxErgazomenos()
    {
    if(getVasikosMisthos()<=12000) {
        return foros=0.01*getVasikosMisthos();
        }
    else if(getVasikosMisthos()>=12000 && getVasikosMisthos()<=16000)
    {
        return foros = 15 / 100 * getVasikosMisthos();
    }
 else if(getVasikosMisthos>=16000 && getVasikosMisthos()<=18500)
    {
     return foros=20/100*getVasikosMisthos();

 }
 else if(getVasikosMisthos()>=18500 &&getVasikosMisthos()<=24000)
    {
    return foros=28/100*(getVasikosMisthos());
 }
 else if(getVasikosMisthos()>=24000 &&getVasikosMisthos()<=28000)
    {
     return foros=35/100*getVasikosMisthos();
 }
 else if(getVasikosMisthos()>=28000 &&getVasikosMisthos()<=36000)
    {
     foros=40/100*getVasikosMisthos();
 }
    return foros;


until 12000 tax is 10% and so on.
Why taxes when i run the program is zero?
Posted
Updated 13-Dec-10 15:58pm
v2

Remove the "return" keyword from all the "if" conditions.

Java
public double taxErgazomenos()
    {
    if(getVasikosMisthos()<=12000) {
        foros=0.01*getVasikosMisthos();
        }
    else if(getVasikosMisthos()>=12000 && getVasikosMisthos()<=16000)
    {
        foros = 15 / 100 * getVasikosMisthos();
    }
 else if(getVasikosMisthos>=16000 && getVasikosMisthos()<=18500)
    {
     foros=20/100*getVasikosMisthos();
 }
 else if(getVasikosMisthos()>=18500 &&getVasikosMisthos()<=24000)
    {
    foros=28/100*(getVasikosMisthos());
 }
 else if(getVasikosMisthos()>=24000 &&getVasikosMisthos()<=28000)
    {
     foros=35/100*getVasikosMisthos();
 }
 else if(getVasikosMisthos()>=28000 &&getVasikosMisthos()<=36000)
    {
     foros=40/100*getVasikosMisthos();
 }
    return foros;
}
 
Share this answer
 
Comments
nikosv 14-Dec-10 23:59pm    
thanks
Sandeep Mewara 15-Dec-10 0:27am    
Can I ask, how and why?
Try:
C#
public double taxErgazomenos()
    {
    if(getVasikosMisthos()&lt;=12000) {
        return 0.01*getVasikosMisthos();
        }
    else if(getVasikosMisthos()&gt;=12000 && getVasikosMisthos()&lt;=16000)
    {
        return 15 / 100 * getVasikosMisthos();
    }
 else if(getVasikosMisthos&gt;=16000 && getVasikosMisthos()&lt;=18500)
    {
     return 20/100*getVasikosMisthos();

 }
 else if(getVasikosMisthos()&gt;=18500 &&getVasikosMisthos()&lt;=24000)
    {
    return 28/100*(getVasikosMisthos());
 }
 else if(getVasikosMisthos()&gt;=24000 &&getVasikosMisthos()&lt;=28000)
    {
     return 35/100*getVasikosMisthos();
 }
 else if(getVasikosMisthos()&gt;=28000 &&getVasikosMisthos()&lt;=36000)
    {
     return 40/100*getVasikosMisthos();
 }
else 
   return 50/100*getVasikosMisthos();
}
 
Share this answer
 
Comments
nikosv 14-Dec-10 23:58pm    
thanks for the answear
Venkatesh Mookkan 15-Dec-10 0:11am    
@Sandeep, the way you specified is a dirty fix.
Venkatesh Mookkan 15-Dec-10 0:46am    
@Sandeep,

You using "else if" statements in the function, then what is use of using "return" statement (return statement is used to return from the function from where it called). If you use "if" statement only, then it make sense but I wouldn't suggest that too. Some day someone will edit your code and he would mess it up, if he misunderstand your logic.

Note:
You can reply to this comment itself ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900