Advertisement
bobo_bobkata

Untitled

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