Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package O7_NestedLoops.Exercise;
- import java.util.Scanner;
- public class Ex09Fishing {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- String command = scanner.nextLine();
- int counterFishes = 0;
- double sumChars = 0;
- double priceFish = 0;
- double earnMoney = 0;
- double pay = 0;
- while (!command.equalsIgnoreCase("Stop")) {
- for (int i = 0; i < command.length(); i++) {
- char c = command.charAt(i);
- int num = (int) c;
- sumChars += num;
- }
- double fishKg = Double.parseDouble(scanner.nextLine());
- priceFish = sumChars/fishKg;
- sumChars = 0;
- counterFishes ++;
- if (counterFishes%3==0) {
- earnMoney += priceFish;
- } else {
- pay += priceFish;
- }
- if (counterFishes == n) {
- System.out.println("Lyubo fulfilled the quota!");
- break;
- } else {
- command = scanner.nextLine();
- }
- }
- double result = earnMoney - pay;
- if (earnMoney>pay) {
- System.out.printf("Lyubo's profit from %d fishes is %.2f leva.", counterFishes, result);
- } else {
- System.out.printf("Lyubo lost %.2f leva today.", Math.abs(result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment