Groney

Fishing 100/100

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