Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SkiTrip {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int nights = Integer.parseInt(scanner.nextLine()) - 1;
- String room = scanner.nextLine();
- String rating = scanner.nextLine();
- int roomPricePerNight = 18,
- apartmentPricePerNight = 25,
- presidentApartmentPerNight = 35;
- double totalSum = 0;
- if (room.equals("room for one person")) {
- totalSum = roomPricePerNight * nights;
- } else if (room.equals("apartment")) {
- totalSum = apartmentPricePerNight * nights;
- if (nights < 10) {
- totalSum *= 0.70;
- } else if (nights < 15) {
- totalSum *= 0.65;
- } else {
- totalSum *= 0.50;
- }
- } else if (room.equals("president apartment")) {
- totalSum = presidentApartmentPerNight * nights;
- if (nights < 10) {
- totalSum *= 0.90;
- } else if (nights < 15) {
- totalSum *= 0.85;
- } else {
- totalSum *= 0.80;
- }
- }
- if (rating.equals("positive")) {
- totalSum *= 1.25;
- } else if (rating.equals("negative")) {
- totalSum *= 0.90;
- }
- System.out.printf("%.2f\n", totalSum);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class SkiTrip {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int nights = Integer.parseInt(scanner.nextLine()) - 1;
- String room = scanner.nextLine();
- String rating = scanner.nextLine();
- int roomPricePerNight = 18,
- apartmentPricePerNight = 25,
- presidentApartmentPerNight = 35;
- double totalSum = nights * switch (room) {
- case "room for one person" -> roomPricePerNight;
- case "apartment" -> apartmentPricePerNight * (nights < 10 ? 0.70 : nights < 15 ? 0.65 : 0.50);
- case "president apartment" -> presidentApartmentPerNight * (nights < 10 ? 0.90 : nights < 15 ? 0.85 : 0.80);
- default -> 0;
- };
- totalSum *= rating.equals("positive") ? 1.25 : 0.90;
- System.out.printf("%.2f\n", totalSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement