Advertisement
Lyubohd

Fishing

Feb 21st, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int quota = Integer.parseInt(scanner.nextLine());
  8.  
  9.         String fishName = scanner.nextLine();
  10.  
  11.         int fishCount = 0;
  12.         double money = 0.0;
  13.  
  14.         while (!"Stop".equals(fishName)) {
  15.             double fishKg = Double.parseDouble(scanner.nextLine());
  16.             fishCount++;
  17.  
  18.             double fishPrice = 0.0;
  19.  
  20.             for (int i = 0; i < fishName.length(); i++) {
  21.                 fishPrice += fishName.charAt(i);
  22.             }
  23.  
  24.             fishPrice /= fishKg;
  25.  
  26.             if (fishCount % 3 == 0) {
  27.                 money += fishPrice;
  28.             } else {
  29.                 money -= fishPrice;
  30.             }
  31.  
  32.             if (fishCount == quota) {
  33.                 System.out.println("Lyubo fulfilled the quota!");
  34.                 break;
  35.             }
  36.  
  37.             fishName = scanner.nextLine();
  38.         }
  39.  
  40.         if (money >= 0) {
  41.             System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", fishCount, money);
  42.         } else {
  43.             System.out.printf("Lyubo lost %.2f leva today.", Math.abs(money));
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement