-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab1_Question5.java
More file actions
54 lines (37 loc) · 1.19 KB
/
Lab1_Question5.java
File metadata and controls
54 lines (37 loc) · 1.19 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package day14_methodsPart2;
public class Lab1_Question5 {
public static void main(String[] args) {
// olcay // Jun 15, 2020
/*Question-5
You are driving a little too fast, and a police officer stops you. Write a method to compute the result:
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.
caughtSpeeding(60, false) → 0
caughtSpeeding(65, false) → 1
caughtSpeeding(65, true) → 0
*/
caughtSpeeding(60, false);
caughtSpeeding(65, false);
caughtSpeeding(65, true);
}
public static void caughtSpeeding(int speed, boolean isBirthday) {
if(!isBirthday) {
if(speed<=60) {
System.out.println(0);
}else if(speed>=61 && speed<=80) {
System.out.println(1);
}else {
System.out.println(2);
}
}else {
if(speed<=65) {
System.out.println(0);
}else if(speed>=66 && speed<=85) {
System.out.println(1);
}else {
System.out.println(2);
}
}
}
}