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