Advertisement
Spocoman

02. Report System

Aug 29th, 2024
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ReportSystem {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int neededSum = Integer.parseInt(scanner.nextLine()),
  7.                 cashSum = 0, cardSum = 0, cashCount = 0, cardCount = 0,
  8.                 counter = 0, sumTransaction;
  9.  
  10.         String input = "";
  11.         while (neededSum > 0 && !(input = scanner.nextLine()).equals("End")) {
  12.             sumTransaction = Integer.parseInt(input);
  13.  
  14.             if (counter % 2 == 0 && sumTransaction > 0 && sumTransaction <= 100) {
  15.                 System.out.println("Product sold!");
  16.                 neededSum -= sumTransaction;
  17.                 cashSum += sumTransaction;
  18.                 cashCount++;
  19.             } else if (counter % 2 == 1 && sumTransaction >= 10) {
  20.                 System.out.println("Product sold!");
  21.                 neededSum -= sumTransaction;
  22.                 cardSum += sumTransaction;
  23.                 cardCount++;
  24.             } else {
  25.                 System.out.println("Error in transaction!");
  26.             }
  27.             counter++;
  28.         }
  29.  
  30.         if (input.equals("End")) {
  31.             System.out.println("Failed to collect required money for charity.");
  32.         } else {
  33.             System.out.printf("Average CS: %.2f\nAverage CC: %.2f\n", 1.0 * cashSum / cashCount, 1.0 * cardSum / cardCount);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement