Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package exercise6;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Fishing {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. int n = Integer.parseInt(scanner.nextLine());
  11. String fish = scanner.nextLine();
  12.  
  13. double profit = 0;
  14. int quota = 0;
  15.  
  16. while (!"Stop".equals(fish)) {
  17. double weight = Double.parseDouble(scanner.nextLine());
  18. double nameInt = fish.length();
  19. double currentFishValue = 0;
  20.  
  21. for (int i = 0; i < nameInt; i++) {
  22. char currentValue = fish.charAt(i); // Намираме стойността на една риба
  23. currentFishValue += currentValue;
  24. }
  25. quota++;
  26. if (quota != 3) {
  27. profit -= currentFishValue / weight;
  28. } else {
  29. profit += currentFishValue / weight;
  30. }
  31.  
  32. if (quota >= n) {
  33. break;
  34. }
  35. fish = scanner.nextLine();
  36. }
  37. if (quota >= n) {
  38. System.out.println("Lyubo fulfilled the quota!");
  39. }
  40. if (profit > 0) {
  41. System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", quota, profit);
  42. } else {
  43. System.out.printf("Lyubo lost %.2f leva today.", Math.abs(profit));
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement