Advertisement
Guest User

Untitled

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