Advertisement
Guest User

EasterDecoration

a guest
Apr 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EasterDecoration {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int numberClients = Integer.parseInt(scanner.nextLine());
  10.  
  11.  
  12. int totalItems = 0;
  13.  
  14. double totalAmountSpent = 0;
  15.  
  16.  
  17. for (int i = 0; i < numberClients; i++) {
  18. double amountSpentByClient = 0;
  19. int numberItemsByClient = 0;
  20.  
  21. String command = scanner.nextLine();
  22. while (!"Finish".equals(command)) {
  23.  
  24.  
  25. if ("basket".equals(command)) {
  26. amountSpentByClient += 1.50;
  27. numberItemsByClient++;
  28. } else if ("wreath".equals(command)) {
  29. amountSpentByClient += 3.80;
  30. numberItemsByClient++;
  31. } else if ("chocolate bunny".equals(command)) {
  32. amountSpentByClient += 7;
  33. numberItemsByClient++;
  34. }
  35. command = scanner.nextLine();
  36.  
  37. }
  38. if (numberItemsByClient % 2 == 0) {
  39. amountSpentByClient *= 0.8;
  40. }
  41.  
  42. totalAmountSpent += amountSpentByClient;
  43.  
  44. System.out.printf("You purchased %d items for %.2f leva.\n", numberItemsByClient, amountSpentByClient);
  45.  
  46. }
  47.  
  48. double avg = totalAmountSpent / numberClients;
  49.  
  50. System.out.printf("Average bill per client is: %.2f leva.", avg);
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement