SophiYo

09Fishing

Dec 16th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package O7_NestedLoops.Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex09Fishing {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.         String command = scanner.nextLine();
  11.         int counterFishes = 0;
  12.         double sumChars = 0;
  13.         double priceFish = 0;
  14.         double earnMoney = 0;
  15.         double pay = 0;
  16.  
  17.         while (!command.equalsIgnoreCase("Stop")) {
  18.  
  19.             for (int i = 0; i < command.length(); i++) {
  20.                char c = command.charAt(i);
  21.                int num = (int) c;
  22.                sumChars += num;
  23.             }
  24.  
  25.             double fishKg = Double.parseDouble(scanner.nextLine());
  26.  
  27.             priceFish = sumChars/fishKg;
  28.  
  29.             sumChars = 0;
  30.             counterFishes ++;
  31.  
  32.             if (counterFishes%3==0) {
  33.                 earnMoney += priceFish;
  34.             } else {
  35.                 pay += priceFish;
  36.             }
  37.  
  38.             if (counterFishes == n) {
  39.                 System.out.println("Lyubo fulfilled the quota!");
  40.                 break;
  41.             } else {
  42.                 command = scanner.nextLine();
  43.             }
  44.         }
  45.  
  46.         double result = earnMoney - pay;
  47.  
  48.         if (earnMoney>pay) {
  49.             System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", counterFishes, result);
  50.         } else {
  51.             System.out.printf("Lyubo lost %.2f leva today.", Math.abs(result));
  52.         }
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment