Advertisement
Guest User

Untitled

a guest
May 15th, 2020
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ReportSystem_02 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scann = new Scanner(System.in);
  7. int salesSum = Integer.parseInt(scann.nextLine());
  8. String input = scann.nextLine();
  9. int count = 0, cash = 0, card = 0, prices = 0, cashPerson = 0, cardPerson = 0, allPrice = 0;
  10. while (!input.equals("End")) {
  11. prices = Integer.parseInt(input);
  12. count++;
  13. if (count % 2 == 0) {
  14. if (prices < 10) {
  15. System.out.println("Error in transaction!");
  16. } else {
  17. cardPerson++;
  18. card += prices;
  19. System.out.println("Product sold!");
  20. allPrice += prices;
  21. }
  22. } else {
  23. if (prices > 100) {
  24. System.out.println("Error in transaction!");
  25. } else {
  26. cashPerson++;
  27. cash += prices;
  28. System.out.println("Product sold!");
  29. allPrice += prices;
  30. }
  31. }
  32.  
  33. if (allPrice > salesSum) {
  34. break;
  35. }
  36. input = scann.nextLine();
  37. }
  38. if (allPrice < salesSum) {
  39. System.out.println("Failed to collect required money for charity.");
  40. } else {
  41. double sumCash = cash * 1.0 / cashPerson;
  42. double sumCard = card * 1.0 / cardPerson;
  43. System.out.printf("Average CS: %.2f%n", sumCash);
  44. System.out.printf("Average CC: %.2f", sumCard);
  45. }
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement