forked from angiejones/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGrossPayInputValidation.java
More file actions
39 lines (27 loc) · 1013 Bytes
/
Copy pathGrossPayInputValidation.java
File metadata and controls
39 lines (27 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package chapter4;
import java.util.Scanner;
/*
* WHILE LOOP:
* Each store employee makes $15 an hour. Write a program that allows the employee
* to enter the number of hours worked for the week. Do not allow overtime.
*/
public class GrossPayInputValidation {
public static void main(String args[]){
//Initialize known variables
int rate = 15;
int maxHours = 40;
//Get input for unknown variables
System.out.println("How many hours did you work this week?");
Scanner scanner = new Scanner(System.in);
double hoursWorked = scanner.nextDouble();
//Validate input
while(hoursWorked > maxHours || hoursWorked < 1){
System.out.println("Invalid entry. Your hours must be between 1 and 40. Try again.");
hoursWorked = scanner.nextDouble();
}
scanner.close();
//Calculate gross
double gross = rate * hoursWorked;
System.out.println("Gross pay: $" + gross);
}
}