Advertisement
A_Marinov

Untitled

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