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 year = scanner.nextLine(),
- type = scanner.nextLine(),
- net = scanner.nextLine();
- int months = Integer.parseInt(scanner.nextLine());
- double price = 0;
- if (type.equals("Small")) {
- if (year.equals("one")) {
- price = 9.98;
- } else {
- price = 8.58;
- }
- } else if (type.equals("Middle")) {
- if (year.equals("one")) {
- price = 18.99;
- } else {
- price = 17.09;
- }
- } else if (type.equals("Large")) {
- if (year.equals("one")) {
- price = 25.98;
- } else {
- price = 23.59;
- }
- } else if (type.equals("ExtraLarge")) {
- if (year.equals("one")) {
- price = 35.99;
- } else {
- price = 31.79;
- }
- }
- if (net.equals("yes")) {
- if (price <= 10) {
- price += 5.50;
- } else if (price <= 30) {
- price += 4.35;
- } else {
- price += 3.85;
- }
- }
- double total = price * months;
- if (year.equals("two")) {
- total -= 3.75 * total / 100;
- }
- System.out.printf("%.2f lv.\n", total);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String year = scanner.nextLine(),
- type = scanner.nextLine(),
- net = scanner.nextLine();
- int months = Integer.parseInt(scanner.nextLine());
- double price = 0;
- switch (type) {
- case "Small" -> {
- if (year.equals("one")) {
- price = 9.98;
- } else {
- price = 8.58;
- }
- }
- case "Middle" -> {
- if (year.equals("one")) {
- price = 18.99;
- } else {
- price = 17.09;
- }
- }
- case "Large" -> {
- if (year.equals("one")) {
- price = 25.98;
- } else {
- price = 23.59;
- }
- }
- case "ExtraLarge" -> {
- if (year.equals("one")) {
- price = 35.99;
- } else {
- price = 31.79;
- }
- }
- }
- if (net.equals("yes")) {
- if (price <= 10) {
- price += 5.50;
- } else if (price <= 30) {
- price += 4.35;
- } else {
- price += 3.85;
- }
- }
- double total = price * months;
- if (year.equals("two")) {
- total -= 3.75 * total / 100;
- }
- System.out.printf("%.2f lv.\n", total);
- }
- }
- Решеие с тернарен оператор:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String year = scanner.nextLine(),
- type = scanner.nextLine(),
- net = scanner.nextLine();
- int months = Integer.parseInt(scanner.nextLine());
- double price =
- (type.equals("Small") ? (year.equals("one") ? 9.98 : 8.58) :
- type.equals("Middle") ? (year.equals("one") ? 18.99 : 17.09) :
- type.equals("Large") ? (year.equals("one") ? 25.98 : 23.59) :
- type.equals("ExtraLarge") ? (year.equals("one") ? 35.99 : 31.79) : 0);
- double total = (price + (net.equals("yes") ? (price <= 10 ? 5.50 : price <= 30 ? 4.35 : 3.85) : 0)) * months;
- total -= year.equals("two") ? 3.75 * total / 100 : 0;
- System.out.printf("%.2f lv.\n", total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement