Advertisement
Spocoman

Darts

Sep 4th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String name = scanner.nextLine(),
  7.                 zone;
  8.         int dots, yesCount = 0, noCount = 0, total = 301;
  9.  
  10.         while (total > 0 && !(zone = scanner.nextLine()).equals("Retire")) {
  11.             dots = Integer.parseInt(scanner.nextLine());
  12.             if (zone.equals("Double")) {
  13.                 dots *= 2;
  14.             } else if (zone.equals("Triple")) {
  15.                 dots *= 3;
  16.             }
  17.  
  18.             if (total < dots) {
  19.                 noCount++;
  20.             } else {
  21.                 total -= dots;
  22.                 yesCount++;
  23.             }
  24.         }
  25.  
  26.         if (total == 0) {
  27.             System.out.println(name + " won the leg with " + yesCount + " shots.");
  28.         } else {
  29.             System.out.println(name + " retired after " + noCount + " unsuccessful shots.");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement