Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P02ReportSystem {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double neededMoney = Integer.parseInt(scanner.nextLine());
- String input = scanner.nextLine();
- double totalMoney = 0;
- double cashMoney = 0;
- int cashCounter = 0;
- double creditCardMoney = 0;
- int creditCardCounter = 0;
- int daysCount = 1;
- while (!input.equals("End")) {
- double currentDonation = Double.parseDouble(input);
- if (daysCount % 2 == 0) { // Credit Card
- if (currentDonation < 10) {
- System.out.println("Error in transaction!");
- } else {
- System.out.println("Product sold!");
- totalMoney += currentDonation;
- creditCardMoney += currentDonation;
- creditCardCounter++;
- }
- } else { // CASH
- if (currentDonation > 100) {
- System.out.println("Error in transaction!");
- } else {
- System.out.println("Product sold!");
- totalMoney += currentDonation;
- cashMoney += currentDonation;
- cashCounter++;
- }
- }
- daysCount++;
- if (totalMoney > neededMoney) {
- break;
- }
- input = scanner.nextLine();
- }
- if (totalMoney > neededMoney) {
- System.out.printf("Average CS: %.2f%n", cashMoney / cashCounter);
- System.out.printf("Average CC: %.2f%n", creditCardMoney / creditCardCounter);
- } else {
- System.out.println("Failed to collect required money for charity.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement