Question

Write a while loop to ask the user to type number of hours(double) they work per...

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

Homework Answers

Answer #1

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");
}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
Write the C++ language statements to ask a user to enter a number within the range...
Write the C++ language statements to ask a user to enter a number within the range of 0 to 100 (0 and 100 are valid inputs). When the value is not valid, you should prompt the user to enter another value. (The user may enter many invalid numbers, so you must use loop). Only after the user enters a valid number should you display the message “Good” and the value of the number.
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
for C++ Write a function containing a while loop that lets the user enter a number....
for C++ Write a function containing a while loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in the variable product . The loop should iterate as long as product contains a value less than 100. Have the function return product.
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
5) Write a java program with scanner object to input first number and second number as...
5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement. Steps: 1) Declare scanner object 2) Ask system out print for first number and declare variable first number 3) Ask system out print for second number and declare variable second number 4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT