Advertisement
drago68

Untitled

Jul 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int quota = Integer.parseInt(scanner.nextLine());
  10. double Save = 0;
  11. double Spend = 0;
  12. String fish = scanner.nextLine();
  13. int counter = 0;
  14. double diff = 0;
  15.  
  16. while (!fish.equals("Stop")) {
  17. counter++;
  18. if (counter == quota) {
  19. System.out.println("Lyubo fulfilled the quota!");
  20. break;
  21. }
  22. double kg = Integer.parseInt(scanner.nextLine());
  23. if (counter%3 == 0) {
  24. for (int i = 0; i <= fish.length() - 1; i++) {
  25. char currentSave = fish.charAt(i);
  26. Save += currentSave;
  27. // if (i == fish.length() - 1) {
  28. Save = Save / kg;
  29. //}
  30. }
  31. }else {
  32. for (int i = 0; i <= fish.length() - 1; i++) {
  33. char currentSpend = fish.charAt(i);
  34. Spend += currentSpend;
  35. // if (i == fish.length() - 1) {
  36. Spend = Spend / kg;
  37. // }
  38. }
  39.  
  40. }
  41. fish=scanner.nextLine();
  42. }
  43. if (Save >= Spend) {
  44. diff = Math.abs(Spend - Save);
  45. System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", counter, diff);
  46. } else {
  47. diff = Math.abs(Spend - Save);
  48. System.out.printf("Lyubo lost %.2f leva today.", diff);
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement