Advertisement
Guest User

Nested Loops - 08. Fishing - JAVA

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