Advertisement
Guest User

Darts - Java

a guest
Apr 4th, 2019
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package exercisesNakovBook;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Darts {
  6. public static void main(String[] args) {
  7. @SuppressWarnings("resource")
  8.  
  9. Scanner sc = new Scanner(System.in);
  10.  
  11. String name = sc.nextLine();
  12. int initialPoints = 301;
  13. int countSuccsess = 0;
  14. int countFail = 0;
  15.  
  16. String input = "";
  17.  
  18. while (!"Retire".equals(input = sc.nextLine())) {
  19. int points = Integer.parseInt(sc.nextLine());
  20.  
  21. switch(input) {
  22. case "Single":
  23. points *= 1;
  24. if (points > initialPoints) {
  25. countFail++;
  26. } else {
  27. initialPoints -= points;
  28. countSuccsess++;
  29. }
  30. break;
  31. case "Double":
  32. points *= 2;
  33. if (points > initialPoints) {
  34. countFail++;
  35. } else {
  36. initialPoints -= points;
  37. countSuccsess++;
  38. }
  39. break;
  40. case "Triple":
  41. points *= 3;
  42. if (points > initialPoints) {
  43. countFail++;
  44. } else {
  45. initialPoints -= points;
  46. countSuccsess++;
  47. }
  48. break;
  49. }
  50.  
  51. if (initialPoints == 0) {
  52. break;
  53. }
  54. }
  55.  
  56. if (initialPoints == 0) {
  57. System.out.printf("%s won the leg with %d shots.", name, countSuccsess);
  58. } else if (input.equals("Retire")) {
  59. System.out.printf("%s retired after %d unsuccessful shots.", name, countFail);
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement