Advertisement
Guest User

Untitled

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