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