Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package WhileLoop;
- import java.util.Scanner;
- public class WeddingDecoration {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- double n = Double.parseDouble(s.nextLine());
- String name = s.nextLine();
- double price = 0;
- int bal = 0;
- int fl = 0;
- int cen = 0;
- int rib = 0;
- double budget = 0;
- while(!name.equals("stop")){
- int balons = Integer.parseInt(s.nextLine());
- if(name.equals("balloons")){
- price += balons * 0.1;
- bal += balons;
- }
- if(name.equals("flowers")){
- price += balons * 1.5;
- fl += balons;
- }
- if(name.equals("candles")){
- price += balons * 0.5;
- cen += balons;
- }
- if(name.equals("ribbon")){
- price += balons * 2;
- rib += balons;
- }
- budget = n - price;
- if(budget <= 0){
- System.out.printf("All money is spent!%n");
- break;
- }
- name = s.nextLine();
- }
- if (name.equals("stop")){
- System.out.printf("Spend money: %.2f%n", price);
- System.out.printf("Money left: %.2f%n", n - price);
- }
- System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", bal, rib, fl, cen );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement