forked from mirandaio/codingbat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaughtSpeeding.java
More file actions
26 lines (25 loc) · 872 Bytes
/
caughtSpeeding.java
File metadata and controls
26 lines (25 loc) · 872 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
/* You are driving a little too fast, and a police officer stops you. Write
* code to compute the result, encoded as an int value: 0=no ticket, 1=small
* ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is
* between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the
* result is 2. Unless it is your birthday -- on that day, your speed can be
* 5 higher in all cases.
*/
public int caughtSpeeding(int speed, boolean isBirthday) {
if(isBirthday) {
if(speed <= 65) {
return 0;
} else if(66 <= speed && speed <= 85) {
return 1;
} else if(86 <= speed) {
return 2;
}
}
if(speed <= 60) {
return 0;
} else if(61 <= speed && speed <= 80) {
return 1;
} else {
return 2;
}
}