Click here to Skip to main content
15,936,802 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to construct a program
that will require the user to input
their salary and your program can
calculate the increment in salary that
will obtain based on the table below.
Using if----else selection control statement.

Salary Increment

N 800 - N1000 2%

N 101 - N2000 5%

N 201 - N4000 8%

N 400 > 10%

What I have tried:

I have tried this code but i wants to know weither i am correct or not. Thanks

Java
import java.util.Scanner;
public class Question2
{
 public static void main(String [] args)throws IOException
 {
  float salary;
  double increment;
 Scanner scanner = new Scanner(new InputStreamReader(System.in));


  System.out.print("Enter Your Salary:");

  salary = scanner.nextFloat();

  if ((salary >=800) && (salary <=1000))

  {
   increment=(2 / salary)*100;
   System.out.println("\nPercentage increment is: " + increment + "\n");
  }
  else if ((salary >=101) && (salary <=2000))
  {
   increment=(5 / salary)*100;
   System.out.println("\nPercentage increment is: " + increment + "\n");
  }
  else if ((salary >=201) && (salary <=4000))
  {
   increment=(8 / salary)*100;
   System.out.println("\nPercentage increment is: " + increment + "\n");
  }
  else if (salary > 400 )
  {
   increment=(10 / salary)*100;
   System.out.println("\nPercentage increment is: " + increment + "\n");
  }
  else
  System.out.println("\nNo More Increment For This Salary\n");

    }
}
Posted
Updated 11-Feb-23 7:51am
v3
Comments
[no name] 1-May-13 21:04pm    
"i have tried this code but i wants to know weither i am correct or not", if it works as you expect it to then it is correct. If it does not work as you expect it to then it is not correct.
Philippe Mori 2-May-13 0:09am    
Are you sure that your condition are the right ones. I think that some numbers are incorrect. For example 101 is probably 1001... It would make sense only if salary is an integer too since people with a salary in between would not have the augmentation. If original number are used things are also inconsistant...
P Uday kishore 2-May-13 1:49am    
is that working fine?if not we can look into it further..
Sudhakar Shinde 2-May-13 4:02am    
If salary is 900 then it will satisfy almost all the conditions. Please have a look at these conditions first.
@sunusi1 4-May-13 13:36pm    
you have talked true, the range of salary is
800-1000
1001-2000
2001-4000
400>

1 solution

You should check the logic behind your code. Do you realize salary ranges overlap?
As Sudhakar Shinde already pointed out, a salary of 900 would satisfy all your conditions (while due to the else if chain, only first condition's statement would be executed.
 
Share this answer
 

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