Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ReportSystem {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int neededSum = Integer.parseInt(scanner.nextLine()),
- cashSum = 0, cardSum = 0, cashCount = 0, cardCount = 0,
- counter = 0, sumTransaction;
- String input = "";
- while (neededSum > 0 && !(input = scanner.nextLine()).equals("End")) {
- sumTransaction = Integer.parseInt(input);
- if (counter % 2 == 0 && sumTransaction > 0 && sumTransaction <= 100) {
- System.out.println("Product sold!");
- neededSum -= sumTransaction;
- cashSum += sumTransaction;
- cashCount++;
- } else if (counter % 2 == 1 && sumTransaction >= 10) {
- System.out.println("Product sold!");
- neededSum -= sumTransaction;
- cardSum += sumTransaction;
- cardCount++;
- } else {
- System.out.println("Error in transaction!");
- }
- counter++;
- }
- if (input.equals("End")) {
- System.out.println("Failed to collect required money for charity.");
- } else {
- System.out.printf("Average CS: %.2f\nAverage CC: %.2f\n", 1.0 * cashSum / cashCount, 1.0 * cardSum / cardCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement