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);
- int days = Integer.parseInt(scanner.nextLine()),
- nights = days - 1;
- String type = scanner.nextLine(),
- rating = scanner.nextLine();
- double price = 0;
- if (nights > 0) {
- if (type.equals("room for one person")) {
- price = 18.00;
- } else if (type.equals("apartment")) {
- price = 25.00;
- if (nights < 10) {
- price *= 0.70;
- } else if (nights > 15) {
- price *= 0.50;
- } else {
- price *= 0.65;
- }
- } else {
- price = 35.00;
- if (nights < 10) {
- price *= 0.90;
- } else if (nights > 15) {
- price *= 0.80;
- } else {
- price *= 0.85;
- }
- }
- if (rating.equals("positive")) {
- price *= 1.25;
- } else {
- price *= 0.90;
- }
- }
- System.out.printf("%.2f\n", price * nights);
- }
- }
- Решение с тернарен оператор:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine()),
- nights = days - 1;
- String type = scanner.nextLine(),
- rating = scanner.nextLine();
- double price =
- nights > 0 ?
- ((type.equals("room for one person") ? 18.00
- : type.equals("apartment") ? 25.00 * (nights < 10 ? 0.70 : nights > 15 ? 0.50 : 0.65)
- : 35.00
- * (nights < 10 ? 0.90 : nights > 15 ? 0.80 : 0.85))
- * (rating.equals("positive") ? 1.25 : 0.90))
- : 0;
- System.out.printf("%.2f\n", price * nights);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement