Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Orders {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine();
- int quantity = Integer.parseInt(scanner.nextLine());
- double price = 0;
- switch (product) {
- case "coffee":
- price = 1.50;
- break;
- case "water":
- price = 1.00;
- break;
- case "coke":
- price = 1.40;
- break;
- case "snacks":
- price = 2.00;
- break;
- }
- System.out.println(new DecimalFormat("0.00##").format(totalPrice(quantity, price)));
- }
- public static double totalPrice(int quantity, double price) {
- double totalPrice = quantity * price;
- return totalPrice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment