Advertisement
veronikaaa86

05. Orders

Oct 6th, 2021
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package methods;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05Orders {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String product = scanner.nextLine();
  10. int quantity = Integer.parseInt(scanner.nextLine());
  11.  
  12. switch (product) {
  13. case "coffee":
  14. getTotalSum(quantity, 1.5);
  15. break;
  16. case "coke":
  17. getTotalSum(quantity, 1.4);
  18. break;
  19. case "water":
  20. getTotalSum(quantity, 1.0);
  21. break;
  22. case "snacks":
  23. getTotalSum(quantity, 2.0);
  24. break;
  25. }
  26. }
  27.  
  28. static void getTotalSum(int quantity, double price) {
  29. double totalSum = quantity * price;
  30. System.out.printf("%.2f", totalSum);
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement