Advertisement
galinyotsev123

ProgBasicsExam9and10March2019-E04darts

Mar 13th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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. int points = Integer.parseInt(scanner.nextLine());
  17.  
  18. if (type.equalsIgnoreCase("Single")) {
  19. score -= points;
  20. if (score >= 0) {
  21. successfulShots++;
  22. } else {
  23. unsuccessfulShots++;
  24. score += points;
  25. }
  26. } else if (type.equalsIgnoreCase("Double")) {
  27. score -= points * 2;
  28. if (score >= 0) {
  29. successfulShots++;
  30. } else {
  31. unsuccessfulShots++;
  32. score += points * 2;
  33. }
  34. } else if (type.equalsIgnoreCase("Triple")) {
  35. score -= points * 3;
  36. if (score >= 0) {
  37. successfulShots++;
  38. } else {
  39. unsuccessfulShots++;
  40. score += points * 3;
  41. }
  42. }
  43.  
  44. if (score == 0) {
  45. System.out.printf("%s won the leg with %.0f shots.", name, successfulShots);
  46. break;
  47. }
  48. type = scanner.nextLine();
  49.  
  50.  
  51. }
  52.  
  53. if ((type.equalsIgnoreCase("Retire"))) {
  54. System.out.printf("%s retired after %.0f unsuccessful shots.", name, unsuccessfulShots);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement