CarmenPop

Untitled

Feb 21st, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public static void main(String[] args) {
  2. Scanner scanner = new Scanner(System.in);
  3. int expectedamount = Integer.parseInt(scanner.nextLine());
  4. int total = 0;
  5. double totalcard = 0;
  6. double totalcash = 0;
  7. int countcash = 0;
  8. int countcard = 0;
  9. int countpayments = 0;
  10. while(true){
  11. String nextLine = scanner.nextLine();
  12. if(nextLine.equals("End")){
  13. System.out.println("Failed to collect required money for charity.");
  14. break;
  15. }
  16. int price = Integer.parseInt(nextLine);
  17. countpayments++;
  18. if(countpayments % 2 == 1){
  19. if(price < 100){
  20. System.out.println("Product sold!");
  21. totalcash += price;
  22. total +=price;
  23. countcash++;
  24. }else {
  25. System.out.println("Error in transaction!");
  26. }
  27. }else{
  28. if(price > 10){
  29. System.out.println("Product sold!");
  30. totalcard += price;
  31. total +=price;
  32. countcard++;
  33. }else {
  34. System.out.println("Error in transaction!");
  35. }
  36. }
  37. if(total >= expectedamount){
  38. System.out.printf("Average CS: %.2f\n", totalcash / countcash);
  39. System.out.printf("Average CC: %.2f", totalcard / countcard);
  40. break;
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment