Advertisement
yovkovbpfps

1

May 4th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 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. System.out.printf("You purchased %d items for %.2f leva.\n",count,average);
  44. }
  45.  
  46. if (people > 1)
  47. {
  48. average /= people;
  49. }
  50. System.out.printf("Average bill per client is: %.2f leva.",average);
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement