Advertisement
Spocoman

Darts Tournament

Sep 4th, 2024 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 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.         int startPoints = Integer.parseInt(scanner.nextLine()),
  7.                 points, moves = 0;
  8.         String command;
  9.  
  10.         while (startPoints > 0) {
  11.             moves ++;
  12.             command = scanner.nextLine();
  13.             if (command.equals("bullseye")) {
  14.                 break;
  15.             }
  16.             points = Integer.parseInt(scanner.nextLine());
  17.             if (command.equals("double ring")) {
  18.                 points *= 2;
  19.             } else if (command.equals("triple ring")) {
  20.                 points *= 3;
  21.             }
  22.             startPoints -= points;
  23.         }
  24.  
  25.         if (startPoints == 0) {
  26.             System.out.println("Congratulations! You won the game in " + moves + " moves!");
  27.         } else if (startPoints < 0) {
  28.             System.out.println("Sorry, you lost. Score difference: " + Math.abs(startPoints) + ".");
  29.         } else {
  30.             System.out.println("Congratulations! You won the game with a bullseye in " + moves + " moves!");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement