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