Groney

Fishing

Oct 22nd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 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.             for (int i = 1; i < 3; i++) {
  23.                 asciiSum = 0;
  24.                 for (int j = 0; j < fish.length(); j++) {
  25.                     asciiSum += fish.charAt(j);
  26.                 }
  27.  
  28.                 money = asciiSum * 1.0 / kg;
  29.                 budget -= money;
  30.                 fish = scan.nextLine();
  31.                 if ("Stop".equals(fish)) {
  32.                     end = true;
  33.                     break;
  34.                 }
  35.                 kg = Double.parseDouble(scan.nextLine());
  36.                 fishCount++;
  37.             }
  38.  
  39.             if (end) {
  40.                 break;
  41.             }
  42.             asciiSum = 0;
  43.             for (int i = 0; i < fish.length(); i++) {
  44.                 asciiSum += fish.charAt(i);
  45.                 money = asciiSum * 1.0 / kg;
  46.             }
  47.             budget += money;
  48.  
  49.             if (fishCount == fishing) {
  50.                 System.out.println("Lyubo fulfilled the quota!");
  51.                 break;
  52.             }
  53.  
  54.             fish = scan.nextLine();
  55.         }
  56.  
  57.         if (budget >= 0) {
  58.             System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", fishCount, budget);
  59.         } else if (budget < 0) {
  60.             System.out.printf("Lyubo lost %.2f leva today.", Math.abs(budget));
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment