Advertisement
marking2112

NLFishing

Oct 23rd, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 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 quota = Integer.parseInt(scanner.nextLine());
  8.         double price = 0;
  9.         int sumChar = 0;
  10.         double toPay = 0;
  11.         double toGet = 0;
  12.         int count = 0;
  13.        
  14.         String input = scanner.nextLine();
  15.        
  16.         while (!input.equals("Stop")) {
  17.            
  18.             for (int i = (input.length() - 1); i >= 0; i--) {
  19.                 char a = input.charAt(i);
  20.                 sumChar += a;
  21.             }
  22.            
  23.             double kilo = Double.parseDouble(scanner.nextLine());
  24.            
  25.             price = sumChar / kilo;
  26.  
  27.             sumChar = 0;
  28.            
  29.             if ((count + 1) % 3 != 0 || (count + 1) == 1) {
  30.                 toPay += price;
  31.             }else if ( (count + 1) % 3 == 0){
  32.                 toGet += price;
  33.             }
  34.            
  35.             count++;
  36.            
  37.             if ( count < (quota )) {
  38.                 input = scanner.nextLine();
  39.             }else {
  40.                 break;
  41.             }
  42.         }
  43.        
  44.         if (count == quota) {
  45.             System.out.println("Lyubo fulfilled the quota!");
  46.         }
  47.        
  48.         double result = toGet - toPay;
  49.         if (toGet > toPay) {
  50.             System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", count, result);
  51.         }else if (toGet < toPay) {
  52.             System.out.printf("Lyubo lost %.2f leva today.", Math.abs(result));
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement