Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double money = Double.parseDouble(input.next());
- String command = input.next();
- int count = 0;
- int boughtProducts = 0;
- double sum = 0;
- double price = 0;
- while (true){
- if(command.equals("Finish")){
- break;
- }
- switch (command){
- case "Star":
- if(count == 2){
- price = 5.69 - 5.69 * 0.3;
- money -= price;
- count = 0;
- }else {
- price = 5.69;
- money -= price;
- count++;
- }
- boughtProducts++;
- break;
- case "Angel":
- if(count == 2){
- price = 8.49 - 8.49 * 0.3;
- money -= price;
- count = 0;
- }else {
- price = 8.49;
- money -= 8.49;
- count++;
- }
- boughtProducts++;
- break;
- case "Lights":
- if(count == 2){
- price = 11.20 - 11.20 * 0.3;
- money -= price;
- count = 0;
- }else {
- price = 11.20;
- money -= 11.20;
- count++;
- }
- boughtProducts++;
- break;
- case "Wreath":
- if(count == 2){
- price = 15.50 - 15.50 * 0.3;
- money -= price;
- count = 0;
- }else {
- price = 15.50;
- money -= price;
- count++;
- }
- boughtProducts++;
- break;
- case "Candle":
- if(count == 2){
- price = 3.59 - 3.59 * 0.3;
- money -= price;
- count = 0;
- }else {
- price = 3.59;
- money -= price;
- count++;
- }
- boughtProducts++;
- break;
- }
- if(money > 0){
- sum += price;
- }
- if(money < 0){
- System.out.format("Not enough money! You need %.2flv more.\n", Math.abs(money));
- System.out.printf("%d items -> %.2flv spent.", boughtProducts - 1, sum);
- break;
- }
- command = input.next();
- }
- System.out.printf("Congratulations! You bought everything!\n");
- System.out.printf("%d items -> %.2flv spent.", boughtProducts, sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement