Advertisement
markopizzy

Untitled

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