Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class NewHouse_03 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //1. крайна цена = брой на цветята * ед. цена (цветето)
- //2. отстъпка
- //3. проверка за бюджета
- String flowerType = scanner.nextLine();
- int flowerCount = Integer.parseInt(scanner.nextLine());
- int budget = Integer.parseInt(scanner.nextLine());
- //тип, име, стойност
- double finalPrice = 0;
- //"Roses", "Dahlias", "Tulips", "Narcissus", "Gladiolus"
- switch (flowerType) {
- case "Roses":
- finalPrice = flowerCount * 5;
- if (flowerCount > 80) {
- finalPrice = finalPrice - 0.10 * finalPrice;
- //finalPrice = 0.90 * finalPrice;
- }
- break;
- case "Dahlias":
- finalPrice = flowerCount * 3.80;
- if (flowerCount > 90) {
- finalPrice = finalPrice - 0.15 * finalPrice;
- //finalPrice = 0.85 * finalPrice;
- }
- break;
- case "Tulips":
- finalPrice = flowerCount * 2.80;
- if (flowerCount > 80) {
- finalPrice = finalPrice - 0.15 * finalPrice;
- //finalPrice = 0.85 * finalPrice;
- }
- break;
- case "Narcissus":
- finalPrice = flowerCount * 3;
- if (flowerCount < 120) {
- finalPrice = finalPrice + 0.15 * finalPrice;
- //finalPrice = 1.15 * finalPrice
- }
- break;
- case "Gladiolus":
- finalPrice = flowerCount * 2.50;
- if (flowerCount < 80) {
- finalPrice = finalPrice + 0.20 * finalPrice;
- }
- break;
- }
- //крайната цена след отстъпката
- //достатъчен: бюджет >= крайната цена
- if (budget >= finalPrice) {
- double leftMoney = budget - finalPrice;
- System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.", flowerCount, flowerType, leftMoney);
- } else { //budget < finalPrice
- double needMoney = finalPrice - budget;
- System.out.printf("Not enough money, you need %.2f leva more.", needMoney);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement