Advertisement
Osiris1002

Untitled

Dec 8th, 2022
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package While_Loop_More_Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Report_System {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int expSum = Integer.parseInt(scan.nextLine());
  9.         String input = scan.nextLine();
  10.  
  11.         int countOfTransactions = 0;
  12.         double counOfCache = 0;
  13.         double countOfCards = 0;
  14.         double sumOfCards = 0.0;
  15.         double sumOfCache = 0.0;
  16.  
  17.  
  18.         while (!"End".equals(input)) {
  19.             int price = Integer.parseInt(input);
  20.             countOfTransactions++;
  21.  
  22.             if (countOfTransactions % 2 != 0 && price <= 100) {
  23.                 counOfCache++;
  24.                 sumOfCache += price;
  25.                 System.out.println("Product sold!");
  26.             } else if (countOfTransactions % 2 == 0 && price >= 10) {
  27.                 countOfCards++;
  28.                 sumOfCards += price;
  29.                 System.out.println("Product sold!");
  30.             } else {
  31.                 System.out.println("Error in transaction!");
  32.             }if (sumOfCache + sumOfCards >= expSum){
  33.                 break;
  34.             }else if("End".equals(input)){
  35.                 break;
  36.             }
  37.             input = scan.nextLine();
  38.  
  39.         }
  40.         if (sumOfCache + sumOfCards >= expSum) {
  41.             System.out.printf("Average CS: %.2f%n", sumOfCache / counOfCache);
  42.             System.out.printf("Average CC: %.2f", sumOfCards / countOfCards);
  43.         } else  {
  44.             System.out.println("Failed to collect required money for charity.");
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement