galinyotsev123

ProgBasics07Nested-Loops-Y09fishing

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