Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exercisesNakovBook;
- import java.util.Scanner;
- public class Darts {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner sc = new Scanner(System.in);
- String name = sc.nextLine();
- int initialPoints = 301;
- int countSuccsess = 0;
- int countFail = 0;
- String input = "";
- while (!"Retire".equals(input = sc.nextLine())) {
- int points = Integer.parseInt(sc.nextLine());
- switch(input) {
- case "Single":
- points *= 1;
- if (points > initialPoints) {
- countFail++;
- } else {
- initialPoints -= points;
- countSuccsess++;
- }
- break;
- case "Double":
- points *= 2;
- if (points > initialPoints) {
- countFail++;
- } else {
- initialPoints -= points;
- countSuccsess++;
- }
- break;
- case "Triple":
- points *= 3;
- if (points > initialPoints) {
- countFail++;
- } else {
- initialPoints -= points;
- countSuccsess++;
- }
- break;
- }
- if (initialPoints == 0) {
- break;
- }
- }
- if (initialPoints == 0) {
- System.out.printf("%s won the leg with %d shots.", name, countSuccsess);
- } else if (input.equals("Retire")) {
- System.out.printf("%s retired after %d unsuccessful shots.", name, countFail);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement