Advertisement
yovkovbpfps

EXAM 20-21 APRIL 06.EASTER DECORATION

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