Advertisement
desislava_topuzakova

04. Darts Tournament

Jun 6th, 2020
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int startPoints = Integer.parseInt(scanner.nextLine());
  7.         //1. startPoints == 0 -> продължава: startPoints > 0
  8.         //2. ако уцели мишената -> ok
  9.         //3. точки< 0
  10.         int count = 0;
  11.         while (startPoints > 0) {
  12.             //играе -> хвърля
  13.             String sector = scanner.nextLine();
  14.             count++;   //броя на ходовете
  15.             if ("bullseye".equals(sector)) {
  16.                 System.out.printf("Congratulations! You won the game with a bullseye in %d moves!", count);
  17.                 break;
  18.             }
  19.             int points = Integer.parseInt(scanner.nextLine());
  20.        
  21.             //"number section", "double ring","triple ring", "bullseye"
  22.             if ("number section".equals(sector)) {
  23.                 startPoints -= points;
  24.             } else if ("double ring".equals(sector)) {
  25.                 startPoints -= points * 2;
  26.             } else if ("triple ring".equals(sector)) {
  27.                 startPoints -= points * 3;
  28.             }
  29.  
  30.             if (startPoints < 0) {
  31.                 System.out.printf("Sorry, you lost. Score difference: %d.", Math.abs(startPoints));
  32.                 break;
  33.             } else if (startPoints == 0){
  34.                 System.out.printf("Congratulations! You won the game in %d moves!", count);
  35.                 break;
  36.             }
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement