Advertisement
CoineTre

JF-LabMethods05.Orders

Feb 5th, 2021
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lab5Orders {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String product = scanner.nextLine();
  7.         int quantity = Integer.parseInt(scanner.nextLine());
  8.         priceCalculation(product,quantity);
  9.  
  10.     }
  11.  
  12.     private static void priceCalculation(String product, int quantity) {
  13.         double price = 0;
  14.         switch (product){
  15.             case"coffee":
  16.                 price = quantity * 1.5;
  17.                 break;
  18.             case"water":
  19.                 price = quantity * 1.00;
  20.                 break;
  21.             case"coke":
  22.                 price = quantity * 1.40;
  23.                 break;
  24.             case"snacks":
  25.                 price = quantity * 2.00;
  26.                 break;
  27.         }
  28.         System.out.printf("%.2f",price);
  29.  
  30.     }
  31. }
  32. /*Write a method that calculates the total price of an order and prints
  33. it on the console. The method should receive one of the following products: coffee, water,
  34. coke, snacks; and a quantity of the product. The prices for a single piece of each product are:
  35. • coffee – 1.50
  36. • water – 1.00
  37. • coke – 1.40
  38. • snacks – 2.00
  39. Print the result rounded to the second decimal place.
  40. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement