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);
- double budget = Double.parseDouble(scanner.nextLine()),
- daySum;
- String destination = scanner.nextLine(),
- season = scanner.nextLine();
- int days = Integer.parseInt(scanner.nextLine());
- if (destination.equals("Dubai")) {
- if (season.equals("Winter")) {
- daySum = 45000;
- } else {
- daySum = 40000;
- }
- daySum *= 0.70;
- } else if (destination.equals("Sofia")) {
- if (season.equals("Winter")) {
- daySum = 17000;
- } else {
- daySum = 12500;
- }
- daySum *= 1.25;
- } else {
- if (season.equals("Winter")) {
- daySum = 24000;
- } else {
- daySum = 20250;
- }
- }
- double totalSum = daySum * days;
- if (totalSum <= budget) {
- System.out.printf("The budget for the movie is enough! We have %.2f leva left!\n", budget - totalSum);
- } else {
- System.out.printf("The director needs %.2f leva more!\n", totalSum - budget);
- }
- }
- }
- Решение с тернарен оператор:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String destination = scanner.nextLine(),
- season = scanner.nextLine();
- int days = Integer.parseInt(scanner.nextLine());
- budget -=
- (destination.equals("Dubai") ? (season.equals("Winter") ? 45000 : 40000) * 0.70 :
- destination.equals("Sofia") ? (season.equals("Winter") ? 17000 : 12500) * 1.25 :
- season.equals("Winter") ? 24000 : 20250) * days;
- System.out.printf(
- budget >= 0
- ? "The budget for the movie is enough! We have %.2f leva left!\n"
- : "The director needs %.2f leva more!\n", Math.abs(budget)
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement