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