Guest User

Untitled

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