Advertisement
Lyubohd

05. Darts Tournament

Feb 22nd, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem05 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int startingPoints = Integer.parseInt(scan.nextLine());
  8.         boolean wonWithBullseye = false;
  9.         int moves = 0;
  10.  
  11.         while (startingPoints > 0) {
  12.             String sector = scan.nextLine();
  13.             moves++;
  14.             if ("bullseye".equals(sector)) {
  15.                 wonWithBullseye = true;
  16.                 break;
  17.             }
  18.             int currentPoints = Integer.parseInt(scan.nextLine());
  19.  
  20.             switch (sector) {
  21.                 case "number section":
  22.                     startingPoints -= currentPoints;
  23.                     break;
  24.                 case "double ring":
  25.                     startingPoints -= currentPoints * 2;
  26.                     break;
  27.                 case "triple ring":
  28.                     startingPoints -= currentPoints * 3;
  29.                     break;
  30.             }
  31.             if (startingPoints < 0) {
  32.                 break;
  33.             }
  34.         }
  35.  
  36.         if (wonWithBullseye) {
  37.             System.out.printf("Congratulations! You won the game with a bullseye in %d moves!", moves);
  38.         } else if (startingPoints == 0) {
  39.             System.out.printf("Congratulations! You won the game in %d moves!", moves);
  40.         } else {
  41.             System.out.printf("Sorry, you lost. Score difference: %d.", Math.abs(startingPoints));
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement