grach

Darts - exam 9-10 March 2019

Apr 22nd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Darts {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int startPoints = 301;
  8.         String playerName = scan.nextLine();
  9.  
  10.         int counter = 0;
  11.         int badCounter = 0;
  12.  
  13.         String command = "";
  14.         while (!"Retire".equals(command)||(startPoints!=0)) {
  15.  
  16.             command = scan.nextLine();
  17.             int newPoints = Integer.parseInt(command);
  18.  
  19.  
  20.             if (newPoints <= startPoints) {
  21.                 switch (command) {
  22.                     case "Single":
  23.                         startPoints -= newPoints;
  24.                         break;
  25.                     case "Double":
  26.                         startPoints -= newPoints * 2;
  27.                         break;
  28.                     case "Triple":
  29.                         startPoints -= newPoints * 3;
  30.                         break;
  31.                 }
  32.                 counter++;
  33.             }
  34.             else {
  35.                 badCounter++;
  36.             }
  37.  
  38.             System.out.println("Good" + counter);
  39.             System.out.println("Bad " + badCounter );
  40.         }
  41.         System.out.println(playerName + counter);
  42.         System.out.println(playerName + badCounter);
  43.     }
  44. }
Add Comment
Please, Sign In to add comment