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