Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String name = scanner.nextLine();
  9.         double score = 301;
  10.         double successfulShots = 0;
  11.         double unsuccessfulShots = 0;
  12.  
  13.         String type = scanner.nextLine();
  14.         while (!(type.equalsIgnoreCase("Retire"))) {
  15.  
  16.  
  17.             int points = Integer.parseInt(scanner.nextLine());
  18.  
  19.             if (type.equalsIgnoreCase("Single")) {
  20.                 score -= points;
  21.                 if (score >= 0) {
  22.                     successfulShots++;
  23.                 } else {
  24.                     unsuccessfulShots++;
  25.                     score += points;
  26.                 }
  27.             } else if (type.equalsIgnoreCase("Double")) {
  28.                 score -= points * 2;
  29.                 if (score >= 0) {
  30.                     successfulShots++;
  31.                 } else {
  32.                     unsuccessfulShots++;
  33.                     score += points * 2;
  34.                 }
  35.             } else if (type.equalsIgnoreCase("Triple")) {
  36.                 score -= points * 3;
  37.                 if (score >= 0) {
  38.                     successfulShots++;
  39.                 } else {
  40.                     unsuccessfulShots++;
  41.                     score += points * 3;
  42.                 }
  43.             }
  44.  
  45.             if (score == 0) {
  46.                 System.out.printf("%s won the leg with %.0f shots.", name, successfulShots);
  47.                 break;
  48.             }
  49.  
  50.  
  51.             type = scanner.nextLine();
  52.         }
  53.  
  54.         if ((type.equalsIgnoreCase("Retire"))) {
  55.             System.out.printf("%s retired after %.0f unsuccessful shots.",name,unsuccessfulShots);
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement