-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDarts.java
More file actions
61 lines (45 loc) · 1.43 KB
/
Copy pathDarts.java
File metadata and controls
61 lines (45 loc) · 1.43 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
55
56
57
58
59
60
61
package PBExams;
import java.util.Scanner;
public class Darts {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int pointsBegin = 301;
boolean flag = false;
int counter = 0;
int counterUn = 0;
String namePlayer = scanner.nextLine();
String input = scanner.nextLine();
while(!input.equals("Retire")){
int points = Integer.parseInt(scanner.nextLine());
counter ++;
int pointsMin = 0;
switch (input){
case "Single":
pointsMin = points;
break;
case "Double":
pointsMin = points * 2;
break;
case "Triple":
pointsMin = points * 3;
break;
}
if( pointsMin > pointsBegin ){
input = scanner.nextLine();
counterUn ++;
continue;
}
pointsBegin -= pointsMin;
if(pointsBegin == 0){
flag = true;
break;
}
input = scanner.nextLine();
}
if(flag){
System.out.printf("%s won the leg with %d shots.",namePlayer,counter - counterUn);
}else {
System.out.printf("%s retired after %d unsuccessful shots.",namePlayer,counterUn);
}
}
}