Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input.
If number of hours is greater than or equal to 0 and less than 5, then: salary = numberofhours * 5, loop continues, the user can type another number
If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user can type another number
If number of hours is greater or equal to 10, and less than 24, then salary = numberofours * 10, loop continues, the user can type another number
If number of hours is negative or (greater or equal to)24, then the loop stops, message "Quit with invalid input" will be printed.
We assume that the user will type numbers only. IN JAVA
import java.util.Scanner;
public class HoursSalary {
public static void main(String args[]) {
double hours,salary;
Scanner sc=new Scanner(System.in);
System.out.println("Enter hours : ");
hours=sc.nextDouble();
while(hours<=24 && hours>=0)
{
if(hours>=0 && hours<5)
{
System.out.println("Salary : "+(hours*5));
}
else if(hours>=5 && hours<10)
{
System.out.println("Salary : "+(hours*8));
}
else if(hours>=10 && hours<24)
{
System.out.println("Salary : "+(hours*10));
}
System.out.println("Enter hours : ");
hours=sc.nextDouble();
}
System.out.println("Quit with invalid input");
}
}
Get Answers For Free
Most questions answered within 1 hours.