Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ConditionalStatementsAdvanced.Exercise;
- import java.util.Scanner;
- public class NewHouse {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String flowers = scanner.nextLine();
- int quantityFlowers = Integer.parseInt(scanner.nextLine());
- int budget = Integer.parseInt(scanner.nextLine());
- double sumPrice = 0.0;
- switch (flowers) {
- case "Roses":
- sumPrice = quantityFlowers * 5.0;
- if (quantityFlowers > 80) {
- sumPrice = sumPrice * 0.9;
- }
- break;
- case "Dahlias":
- sumPrice = quantityFlowers * 3.80;
- if (quantityFlowers > 90) {
- sumPrice = sumPrice * 0.85;
- }
- break;
- case "Tulips":
- sumPrice = quantityFlowers * 2.80;
- if (quantityFlowers > 80) {
- sumPrice = sumPrice * 0.85;
- }
- break;
- case "Narcissus":
- sumPrice = quantityFlowers * 3.0;
- if (quantityFlowers < 120) {
- sumPrice = sumPrice * 1.15;
- }
- break;
- case "Gladiolus":
- sumPrice = quantityFlowers * 2.50;
- if (quantityFlowers < 80) {
- sumPrice = sumPrice * 1.20;
- }
- break;
- default:
- break;
- }
- if (sumPrice <= budget) {
- double leftSum = budget - sumPrice;
- System.out.printf("Hey, you have a great garden with %d %s " +
- "and %.2f leva left.", quantityFlowers, flowers, leftSum);
- } else {
- double enoght = sumPrice - budget;
- System.out.printf("Not enough money, you need %.2f leva more.", enoght);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement