desislava_topuzakova

04. Balls

May 22nd, 2021
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PrintAndSum_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int countBalls = Integer.parseInt(scanner.nextLine());
  7.         int totalPoints = 0; //общо точки
  8.         int countRed = 0; //брой червени топки
  9.         int countOrange = 0; //брой оранжеви топки
  10.         int countYellow = 0; //брой жълтите топки
  11.         int countWhite = 0; //брой на белите топки
  12.         int countOthers = 0; //брой на останалите топки
  13.         int countBlack = 0; //брой на черните топки
  14.         //за всяка топка от 1 до последната -> четем цвят
  15.         for (int ball = 1; ball <= countBalls; ball++) {
  16.             String color = scanner.nextLine();
  17.             switch(color) {
  18.                 case "red":
  19.                     totalPoints += 5; //totalPoints = totalPoints + 5;
  20.                     countRed++;
  21.                     break;
  22.                 case "orange":
  23.                     totalPoints += 10; //totalPoints = totalPoints + 10;
  24.                     countOrange++;
  25.                     break;
  26.                 case "yellow":
  27.                     totalPoints += 15; //totalPoints = totalPoints + 15;
  28.                     countYellow++;
  29.                     break;
  30.                 case "white":
  31.                     totalPoints += 20; //totalPoints = totalPoints + 20;
  32.                     countWhite++;
  33.                     break;
  34.                 case "black":
  35.                     totalPoints /= 2; //totalPoints = totalPoints / 2;
  36.                     countBlack++;
  37.                     break;
  38.                 default:
  39.                     countOthers++;
  40.                     break;
  41.             }
  42.         }
  43.  
  44.         System.out.println("Total points: " + totalPoints);
  45.         System.out.println("Points from red balls: " + countRed);
  46.         System.out.println("Points from orange balls: " + countOrange);
  47.         System.out.println("Points from yellow balls: " + countYellow);
  48.         System.out.println("Points from white balls: " + countWhite);
  49.         System.out.println("Other colors picked: " + countOthers);
  50.         System.out.println("Divides from black balls: " + countBlack);
  51.  
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment