Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String playerName = scanner.nextLine();
- int countPlays = Integer.parseInt(scanner.nextLine());
- int countVolleyball = 0;
- int countTennis = 0;
- int countBadminton = 0;
- double pointsVolleyball = 0;
- double pointsTennis = 0;
- double pointsBadminton = 0;
- for (int games = 1; games <= countPlays; games++) {
- String gameName = scanner.nextLine(); //"volleyball", "tennis", "badminton"
- int points = Integer.parseInt(scanner.nextLine());
- //за всеки спорт -> средно аритметичното (пъти + общ брой точки)
- if (gameName.equals("volleyball")) {
- countVolleyball++;
- //7% бонус
- pointsVolleyball += points + 0.07 * points;
- } else if (gameName.equals("tennis")) {
- countTennis++;
- pointsTennis += points + 0.05 * points;
- } else if (gameName.equals("badminton")) {
- countBadminton++;
- pointsBadminton += points + 0.02 * points;
- }
- }
- //за всеки спорт -> колко пъти е игран и колко общо точки имаме от него
- //средно аритм = сум от точките / бр. пъти
- double averageVolleyball = pointsVolleyball / countVolleyball;
- double averageTennis = pointsTennis / countTennis;
- double averageBadminton = pointsBadminton / countBadminton;
- double totalPoints = Math.floor(pointsVolleyball + pointsBadminton + pointsTennis);
- //печелим
- if (averageVolleyball >= 75 && averageTennis >= 75 && averageBadminton >= 75){
- System.out.printf("Congratulations, %s! You won the cruise games with %.0f points.", playerName, totalPoints);
- } else {
- System.out.printf("Sorry, %s, you lost. Your points are only %.0f.", playerName, totalPoints);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement