Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine()),
- date = Double.parseDouble(scanner.nextLine()),
- price;
- if (date <= 15) {
- if (type.equals("Cake")) {
- price = 24.00;
- } else if (type.equals("Souffle")) {
- price = 6.66;
- } else {
- price = 12.60;
- }
- } else {
- if (type.equals("Cake")) {
- price = 28.70;
- } else if (type.equals("Souffle")) {
- price = 9.80;
- } else {
- price = 16.98;
- }
- }
- double sum = price * quantity;
- if (date <= 22) {
- if (sum >= 100 && sum <= 200) {
- sum -= sum * 0.15;
- } else if (sum > 200) {
- sum -= sum * 0.25;
- }
- }
- if (date <= 15) {
- sum -= sum * 0.10;
- }
- System.out.printf("%.2f\n", sum);
- }
- }
- Решение с тернарен оператор:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine()),
- date = Double.parseDouble(scanner.nextLine()),
- sum = (date <= 15 ? (type.equals("Cake") ? 24.00 : type.equals("Souffle") ? 6.66 : 12.60) :
- (type.equals("Cake") ? 28.70 : type.equals("Souffle") ? 9.80 : 16.98)) * quantity;
- sum *= (date <= 22 ? (sum > 200 ? 0.75 : sum >= 100 ? 0.85 : 1) : 1) * (date <= 15 ? 0.90 : 1);
- System.out.printf("%.2f\n", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement