Question

In: Computer Science

Write a Java program that will ask the user for his/her salary (numerical integer salary) and...

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.

Solutions

Expert Solution

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:


Related Solutions

Write a Java program that will ask the user for his/her mark (numerical integer mark) and...
Write a Java program that will ask the user for his/her mark (numerical integer mark) and then convert this numerical mark into letter grades. The following is a guideline to the grading scale used. The numeric range within parenthesis maps to the preceding letter grade. If the user gave you a number greater than 100 or less than 0, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use...
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
Write a program to find the prime numbers IN JAVA Ask user to input the integer...
Write a program to find the prime numbers IN JAVA Ask user to input the integer number test the number whether it is a prime number or not Then, print “true” or “false” depending on whether the number is prime or isn’t. Hint: number is prime when is has exactly 2 factors: one and itself. By this definition, number 1 is a special case and is NOT a prime. Use idea of user input, cumulative sum, and loop to solve...
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
c++ Write a program that will ask the user for three pairs of integer values. The...
c++ Write a program that will ask the user for three pairs of integer values. The program will then display whether the first number of the pair is multiple of the second. The actual work of making the determination will be performed by a function called IsMultiple that takes two integer arguments (say, x and y). The function will return a Boolean result of whether x is a multiple of y.
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
(8 marks) Write a program to ask user to enter an integer that represents the number...
Write a program to ask user to enter an integer that represents the number of elements, then generate an ArrayList containing elements which are all random integers in range [75, 144] , and finally display index and value of each element. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use ArrayList. Your program must use only printf(…) statements to adjust the alignment of your output. Your code must display the index in descending...
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT