Advertisement
veronikaaa86

02. Report System

Aug 6th, 2022
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LiveExample {
  4.     public static void main (String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int target = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int totalSum = 0;
  10.         int cashSum = 0;
  11.         int cardSum = 0;
  12.         int countTotal = 0;
  13.         int countCash = 0;
  14.         int countCard = 0;
  15.         String input = scanner.nextLine();
  16.         while (!input.equals("End")) {
  17.             countTotal++;
  18.             int currentAmount = Integer.parseInt(input);
  19.  
  20.             if (countTotal % 2 != 0) {
  21.                 if (currentAmount <= 100) {
  22.                     countCash++;
  23.                     cashSum += currentAmount;
  24.                     totalSum += currentAmount;
  25.                     System.out.println("Product sold!");
  26.                 } else {
  27.                     System.out.println("Error in transaction!");
  28.                 }
  29.             } else {
  30.                 if (currentAmount >= 10) {
  31.                     countCard++;
  32.                     cardSum += currentAmount;
  33.                     totalSum += currentAmount;
  34.                     System.out.println("Product sold!");
  35.                 } else {
  36.                     System.out.println("Error in transaction!");
  37.                 }
  38.             }
  39.  
  40.             if (totalSum >= target) {
  41.                 break;
  42.             }
  43.  
  44.             input = scanner.nextLine();
  45.         }
  46.  
  47.         if (!input.equals("End")) {
  48.             double avgCash = cashSum * 1.0 / countCash;
  49.             double avgCard = cardSum * 1.0 / countCard;
  50.             System.out.printf("Average CS: %.2f%n", avgCash);
  51.             System.out.printf("Average CC: %.2f%n", avgCard);
  52.         } else {
  53.             System.out.println("Failed to collect required money for charity.");
  54.         }
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement