Didart

Orders

Oct 7th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.text.DecimalFormat;
  3. import java.util.Scanner;
  4.  
  5. public class Orders {
  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.         double price = 0;
  13.         switch (product) {
  14.             case "coffee":
  15.                 price = 1.50;
  16.                 break;
  17.             case "water":
  18.                 price = 1.00;
  19.                 break;
  20.             case "coke":
  21.                 price = 1.40;
  22.                 break;
  23.             case "snacks":
  24.                 price = 2.00;
  25.                 break;
  26.         }
  27.         System.out.println(new DecimalFormat("0.00##").format(totalPrice(quantity, price)));
  28.     }
  29.  
  30.     public static double totalPrice(int quantity, double price) {
  31.         double totalPrice = quantity * price;
  32.         return totalPrice;
  33.     }
  34.  
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment