SHARE
TWEET

04. Darts Tournament

desislava_topuzakova Jun 6th, 2020 957 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top