Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MatchTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String category = scanner.nextLine();
- int people = Integer.parseInt(scanner.nextLine());
- double sum = 0;
- if (people >= 1 && people <= 4) {
- budget *= 0.25;
- } else if (people > 4 && people <= 9) {
- budget *= 0.40;
- } else if (people > 9 && people <= 24) {
- budget *= 0.50;
- } else if (people > 24 && people < 50) {
- budget *= 0.60;
- } else {
- budget *= 0.75;
- }
- if (category.equals("VIP")) {
- sum = 499.99 * people;
- } else if (category.equals("Normal")) {
- sum = 249.99 * people;
- }
- if (budget >= sum) {
- System.out.printf("Yes! You have %.2f leva left.", budget - sum);
- } else {
- System.out.printf("Not enough money! You need %.2f leva.", sum - budget);
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class MatchTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String category = scanner.nextLine();
- int people = Integer.parseInt(scanner.nextLine());
- budget *=
- people >= 1 && people <= 4 ? 0.25 :
- people > 4 && people <= 9 ? 0.40 :
- people > 9 && people <= 24 ? 0.50 :
- people > 24 && people < 50 ? 0.60 : 0.75;
- double sum = (category.equals("VIP") ? 499.99 : 249.99) * people;
- if (budget >= sum) {
- System.out.printf("Yes! You have %.2f leva left.", budget - sum);
- } else {
- System.out.printf("Not enough money! You need %.2f leva.", sum - budget);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement