Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab5Orders {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine();
- int quantity = Integer.parseInt(scanner.nextLine());
- priceCalculation(product,quantity);
- }
- private static void priceCalculation(String product, int quantity) {
- double price = 0;
- switch (product){
- case"coffee":
- price = quantity * 1.5;
- break;
- case"water":
- price = quantity * 1.00;
- break;
- case"coke":
- price = quantity * 1.40;
- break;
- case"snacks":
- price = quantity * 2.00;
- break;
- }
- System.out.printf("%.2f",price);
- }
- }
- /*Write a method that calculates the total price of an order and prints
- it on the console. The method should receive one of the following products: coffee, water,
- coke, snacks; and a quantity of the product. The prices for a single piece of each product are:
- • coffee – 1.50
- • water – 1.00
- • coke – 1.40
- • snacks – 2.00
- Print the result rounded to the second decimal place.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement