Advertisement
Guest User

Untitled

a guest
Jan 26th, 2021
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. package WhileLoop.MoreExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ReportSystem {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int sumEnd = Integer.parseInt(scanner.nextLine());
  10.         String input = scanner.nextLine();
  11.  
  12.         int counter = 0;
  13.         int averageCS = 0;
  14.         int averageCC = 0;
  15.         int counterCS = 0;
  16.         int counterCC = 0;
  17.         int total = 0;
  18.         boolean isOK = false;
  19.  
  20.         while (!input.equals("End")) {
  21.             counter++;
  22.             int price = Integer.parseInt(input);
  23.  
  24.             if (counter % 2 == 0) {        // плащане с карта
  25.                 if (price < 10) {
  26.                     System.out.println("Error in transaction!");
  27.                 } else {
  28.                     System.out.println("Product sold!");
  29.                     averageCC = averageCC + price;
  30.                     total = total + price;
  31.                     counterCC++;
  32.                 }
  33.             } else {                     // плащане в брой
  34.                 if (price > 100) {
  35.                     System.out.println("Error in transaction!");
  36.                 } else {
  37.                     System.out.println("Product sold!");
  38.                     averageCS = averageCS + price;
  39.                     total = total + price;
  40.                     counterCS++;
  41.                 }
  42.             }
  43.             if (total >= sumEnd) {
  44.                 isOK = true;
  45.                 break;
  46.             }
  47.  
  48.             input = scanner.nextLine();
  49.         }
  50.  
  51.         if (isOK) {
  52.             System.out.printf("Average CS: %.2f\n", 1.0 * averageCS / counterCS);
  53.             System.out.printf("Average CC: %.2f", 1.0 * averageCC / counterCC);
  54.         } else {
  55.             System.out.println("Failed to collect required money for charity.");
  56.         }
  57.  
  58.     }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement