Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package SelfTestExams.NovemberExam2018Part2;
- import java.util.Scanner;
- public class WeddingDec {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double budget = Double.parseDouble(scan.nextLine());
- String stock = scan.nextLine();
- double spent = 0;
- double price = 0;
- int ballCount = 0;
- int flowCount = 0;
- int candCount = 0;
- int ribCount = 0;
- while (!"stop".equals(stock)) {
- int num = Integer.parseInt(scan.nextLine());
- if (spent > budget) {
- System.out.println("All money is spent!");
- break;
- }
- switch (stock) {
- case "balloons":
- price = 0.1 * num;
- ballCount += num;
- break;
- case "flowers":
- price = 1.5 * num;
- flowCount += num;
- break;
- case "candles":
- price = 0.5 * num;
- candCount += num;
- break;
- case "ribbon":
- price = 2 * num;
- ribCount += num;
- break;
- }
- spent += price;
- if (spent >= budget) {
- System.out.println("All money is spent!");
- break;
- }
- stock = scan.nextLine();
- }
- if (budget > spent) {
- System.out.printf("Spend money: %.2f\n", spent);
- System.out.printf("Money left: %.2f\n", Math.abs(budget - spent));
- }
- System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", ballCount, ribCount, flowCount, candCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment