Advertisement
Guest User

Fishing

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