Ligh7_of_H3av3n

FixedCode 01_BurgerBus

Feb 18th, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package PodgotovkaZaIzpit;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class BurgerBus {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int numCities = Integer.parseInt(scanner.nextLine());
  10.         double totalProfit = 0;
  11.  
  12.         for (int i = 0; i < numCities; i++) {
  13.             String cityName = scanner.nextLine();
  14.             double income = Double.parseDouble(scanner.nextLine());
  15.             double expenses = Double.parseDouble(scanner.nextLine());
  16.  
  17.             double profit = income - expenses;
  18.             if ((i + 1) % 3 == 0) {
  19.                 profit -= expenses * 0.5; // Subtract 50% expenses for special event
  20.             }
  21.             if ((i + 1) % 5 == 0) {
  22.                 profit -= income * 0.1; // Subtract 10% loss due to rain
  23.             }
  24.  
  25.             totalProfit += profit;
  26.  
  27.             System.out.printf("In %s Burger Bus earned %.2f leva.%n", cityName, profit);
  28.         }
  29.  
  30.         System.out.printf("Burger Bus total profit: %.2f leva.%n", totalProfit);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment