Advertisement
svephoto

Fishing

Nov 22nd, 2019
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 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 fishes = Integer.parseInt(scanner.nextLine());
  8.  
  9. double income = 0;
  10. double outcome = 0;
  11. boolean fullFilth = false;
  12. int fishCount = 0;
  13.  
  14. for (int i = 1; i <= fishes; i++) {
  15. String name = scanner.nextLine();
  16.  
  17. if ("Stop".equals(name)) {
  18. fullFilth = true;
  19. break;
  20. }
  21.  
  22. double kg = Double.parseDouble(scanner.nextLine());
  23. int currentFishPrice = 0;
  24.  
  25. for (int j = 0; j < name.length(); j++) {
  26. int value = name.charAt(j);
  27. currentFishPrice += value;
  28. }
  29.  
  30. fishCount++;
  31.  
  32. double price = currentFishPrice * 1.00 / kg;
  33.  
  34. if (fishCount % 3 == 0) {
  35. income += price;
  36. } else {
  37. outcome += price;
  38. }
  39. }
  40.  
  41. if (!fullFilth) {
  42. System.out.println("Lyubo fulfilled the quota!");
  43. }
  44.  
  45. if (income >= outcome) {
  46. System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", fishCount, income - outcome);
  47. } else {
  48. System.out.printf("Lyubo lost %.2f leva today.", Math.abs(income - outcome));
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement