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 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...
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...
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
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
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT