grach

Darts - Exam Preparation

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