Advertisement
Valantina

DartsTournament/EX/27.07.2019/Java

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