In: Computer Science
Write a Java program that will ask the user for his/her salary (numerical integer salary) and then convert this numerical salary into income class. The following is a guideline to the income class used. The numeric range within parenthesis maps to the preceding class. If the user gave you a number greater than 700,000 or less than 10,000, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use if-else.
Income Mapping
Very high (200,000 to 700,000)
High (150,000 to 199,999)
Upper Middle (100,000 to 149,999)
Middle (70,000 to 99,999)
Lower Middle (50,000 to 69,999)
Low (20,000 to 49,999)
Very Low (10,000 to 19,999)
Sample input and output:
Please input your salary: 85000
Your income class is a middle.
Java code:
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
//initializing salary
int salary;
//asking for salary
System.out.print("Please input your salary: ");
//accepting salary
salary=input.nextInt();
//checking if the salary is greater than 700000
if(salary>700000)
//printing Input is invalid
System.out.println("Input is invalid");
//checking if the salary is greater than 200000
else if(salary>=200000)
//printing Very high
System.out.println("Your income class is a Very
high.");
//checking if the salary is greater than 150000
else if(salary>=150000)
//printing High
System.out.println("Your income class is a
High.");
//checking if the salary is greater than 100000
else if(salary>=100000)
//printing Upper Middle
System.out.println("Your income class is a Upper
Middle.");
//checking if the salary is greater than 70000
else if(salary>=70000)
//printing Middle
System.out.println("Your income class is a
Middle.");
//checking if the salary is greater than 50000
else if(salary>=50000)
//printing Lower Middle
System.out.println("Your income class is a Lower
Middle.");
//checking if the salary is greater than 20000
else if(salary>=20000)
//printing Low
System.out.println("Your income class is a
Low.");
//checking if the salary is greater than 10000
else if(salary>=10000)
//printing Very Low
System.out.println("Your income class is a Very
Low.");
else
//printing Input is invalid
System.out.println("Input is invalid");
}
}
Screenshot:
Input and Output: