Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String product = scanner.nextLine();
- int quantity = 0;
- double TotalPrice = 0;
- double price = 0;
- while (!product.equals("Finish")) {
- //Star Angel Lights Wreath Candle
- //5.69 8.49 11.20 15.50 3.59
- if (product.equals("Star")) {
- quantity++;
- price = 5.69;
- if (quantity % 3 == 0) {
- price = price * 0.70;
- }
- TotalPrice += price;
- } else if (product.equals("Angel")) {
- quantity++;
- price = 8.49;
- if (quantity % 3 == 0) {
- price = price * 0.70;
- }
- TotalPrice += price;
- } else if (product.equals("Lights")) {
- quantity++;
- price = 11.20;
- if (quantity % 3 == 0) {
- price = price * 0.70;
- }
- TotalPrice += price;
- } else if (product.equals("Wreath")) {
- quantity++;
- price = 15.50;
- if (quantity % 3 == 0) {
- price = price * 0.70;
- }
- TotalPrice += price;
- } else if (product.equals("Candle")) {
- quantity++;
- price = 3.59;
- if (quantity % 3 == 0) {
- price = price * 0.70;
- }
- TotalPrice += price;
- }
- budget-=price;
- if (budget <= 0) {
- System.out.printf("Not enough money! You need %.2f%n lv more.", Math.abs(TotalPrice - budget));
- break;
- }
- product = scanner.nextLine();
- }
- System.out.println("Congratulations! You bought everything!");
- System.out.printf("%d items -> %.2f lv spent.", quantity, TotalPrice);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement