Професионална програма
Loading...
denkaty avatar denkaty 0 Точки

3. Vacation

https://softuni.bg/trainings/resources/officedocument/49522/basic-syntax-conditional-statements-and-loops-exercise-java-fundamentals-may-2020/2831
Judge ми дава 91/100. Къде греша?

import java.util.Scanner;

public class Vacation {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int people = Integer.parseInt(scanner.nextLine());
        String type = scanner.nextLine();
        String day = scanner.nextLine();

        double singlePrice = 0;
        double totalPrice = 0;

        if (day.equals("Friday")) {
            if ("Students".equals(type)) {
                singlePrice = 8.45;
                totalPrice = people * singlePrice;
                if (people >= 30){
                    totalPrice= totalPrice - (totalPrice * 0.15);
                }
            } else if ("Business".equals(type)) {
                singlePrice = 10.90;
                totalPrice = people * singlePrice;
                if (people >= 100){
                    totalPrice= (people - 10) * singlePrice;
                }
            } else if ("Regular".equals(type)) {
                singlePrice = 15;
                totalPrice = people * singlePrice;
                if (people >= 10 && people <= 20){
                    totalPrice = totalPrice - (totalPrice * 0.05);
                }
            }
        } else if (day.equals("Saturday")) {
            if ("Students".equals(type)) {
                singlePrice = 9.80;
                totalPrice = people * singlePrice;
                if (people >= 30){
                    totalPrice= totalPrice - (totalPrice * 0.15);
                }
            } else if ("Business".equals(type)) {
                singlePrice = 15.60;
                totalPrice = people * singlePrice;
                if (people >= 100){
                    totalPrice= totalPrice - (10 * 10.98);
                }
            } else if ("Regular".equals(type)) {
                singlePrice = 20;
                totalPrice = people * singlePrice;
                if (people >= 10 && people <= 20){
                    totalPrice = totalPrice - (totalPrice * 0.05);
                }
            }
        } else if (day.equals("Sunday")) {
            if ("Students".equals(type)) {
                singlePrice = 10.46;
                totalPrice = people * singlePrice;
                if (people >= 30){
                    totalPrice= totalPrice - (totalPrice * 0.15);
                }
            } else if ("Business".equals(type)) {
                singlePrice = 16;
                totalPrice = people * singlePrice;
                if (people >= 100){
                    totalPrice= totalPrice - (10 * 10.98);
                }
            } else if ("Regular".equals(type)) {
                singlePrice = 22.50;
                totalPrice = people * singlePrice;
                if (people >= 10 && people <= 20){
                    totalPrice = totalPrice - (totalPrice * 0.05);
                }
            }
        }
        System.out.printf("Total price: %.2f%n", totalPrice);

    }
}
0
Fundamentals Module 30/06/2020 16:10:38
Svetsyn avatar Svetsyn 1 Точки

Здравей,

Грешката ти е в следния фрагмент:

}else if (day.equals("Saturday")) {
            if ("Students".equals(type)) {
                singlePrice = 9.80;
                totalPrice = people * singlePrice;
                if (people >= 30){
                    totalPrice= totalPrice - (totalPrice * 0.15);
                }
            } else if ("Business".equals(type)) {
                singlePrice = 15.60;
                totalPrice = people * singlePrice;
                if (people >= 100){
                    totalPrice= totalPrice - (10 * 10.98);

}

.....По условие в тази клауза отстъпката която трябва да извадиш е за 10 човека е по 15.60 и така излиза резултатът!

Поздрави,

Svetsyn

0
01/07/2020 15:22:25