Advertisement
veronikaaa86

04. Balls

Jun 18th, 2022
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04Balls {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int countBalls = Integer.parseInt(scanner.nextLine());
  10.  
  11. int redCount = 0;
  12. int orangeCount = 0;
  13. int yellowCount = 0;
  14. int whiteCount = 0;
  15. int blackCount = 0;
  16. int otherCount = 0;
  17. int sum = 0;
  18. for (int i = 0; i < countBalls; i++) {
  19. String colorBall = scanner.nextLine();
  20.  
  21. switch (colorBall) {
  22. case "red":
  23. redCount++;
  24. sum += 5;
  25. break;
  26. case "orange":
  27. orangeCount++;
  28. sum += 10;
  29. break;
  30. case "yellow":
  31. yellowCount++;
  32. sum += 15;
  33. break;
  34. case "white":
  35. whiteCount++;
  36. sum += 20;
  37. break;
  38. case "black":
  39. blackCount++;
  40. sum = sum / 2;
  41. break;
  42. default:
  43. otherCount++;
  44. }
  45. }
  46.  
  47. System.out.printf("Total points: %d%n", sum);
  48. System.out.printf("Red balls: %d%n", redCount);
  49. System.out.printf("Orange balls: %d%n", orangeCount);
  50. System.out.printf("Yellow balls: %d%n", yellowCount);
  51. System.out.printf("White balls: %d%n", whiteCount);
  52. System.out.printf("Other colors picked: %d%n", otherCount);
  53. System.out.printf("Divides from black balls: %d%n", blackCount);
  54. }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement