Phone Bill JAVA

Мога ли да видя от някъде входа за Test case #5 на задача Phone Bill , защото само той ми гърми, а не мога да открия причината.

Test case #5: Wrong Answer [0.1 s, 27.8 MB]
Your output (clipped)
0 additional messages for 0.00 levas
0 additional minutes for 0.

1 Like

Здравей :slight_smile:

Няма как да видиш теста. Това, което можеш да направиш е да споделиш решението си и да помислим къде може да има пропуск.

Пешо

Решението е споделно в първия ми пост. Или е видимо за мен, че за пръв път ползвам pastebin.

1 Like

Здравей,
Добавих едно = при третия if в твоя код и задачата минава.

Решение
import java.util.Scanner;
 
public class PhoneBill {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
 
        Integer totalAmountOfMessages = Integer.parseInt(scanner.nextLine());
        Integer totalAmountOfMinutes = Integer.parseInt(scanner.nextLine());
 
        Double planTaxes = 12.00;
        Double minuteCost = 0.10;
        Double messagePrice = 0.06;
 
        Integer additionalMessage = 0;
        Integer additionalMinutes = 0;
        Double priceForAdditionalMessages;
        Double priceForAdditionalMinutes;
        Double additionalTaxesPaid;
        Double finalPrice;
 
        if (totalAmountOfMessages > 20 && totalAmountOfMinutes > 60) {
            additionalMessage = totalAmountOfMessages - 20;
            priceForAdditionalMessages = messagePrice * additionalMessage;
            System.out.printf("%d additional messages for %.2f levas%n", additionalMessage, priceForAdditionalMessages);
 
            additionalMinutes = totalAmountOfMinutes - 60;
            priceForAdditionalMinutes = minuteCost * additionalMinutes;
            System.out.printf("%d additional minutes for %.2f levas%n", additionalMinutes, priceForAdditionalMinutes);
 
            additionalTaxesPaid = ((additionalMessage * messagePrice + additionalMinutes * minuteCost) / 100) * 20;
            System.out.printf("%.2f additional taxes%n", additionalTaxesPaid);
 
            finalPrice = 12 + priceForAdditionalMessages + priceForAdditionalMinutes + additionalTaxesPaid;
            System.out.printf("%.2f total bill", finalPrice);
        } else if (totalAmountOfMessages > 20 && totalAmountOfMinutes < 60) {
 
            additionalMessage = totalAmountOfMessages - 20;
            priceForAdditionalMessages = messagePrice * additionalMessage;
            System.out.printf("%d additional messages for %.2f levas%n", additionalMessage, priceForAdditionalMessages);
            System.out.println("0 additional minutes for 0.00 levas");
 
 
            additionalTaxesPaid = ((additionalMessage * messagePrice) / 100) * 20;
            System.out.printf("%.2f additional taxes%n", additionalTaxesPaid);
 
            finalPrice = 12 + priceForAdditionalMessages + additionalTaxesPaid;
            System.out.printf("%.2f total bill", finalPrice);
        } else if (totalAmountOfMessages <= 20 && totalAmountOfMinutes > 60) {
 
            System.out.println("0 additional messages for 0.00 levas");
 
            additionalMinutes = totalAmountOfMinutes - 60;
            priceForAdditionalMinutes = minuteCost * additionalMinutes;
            System.out.printf("%d additional minutes for %.2f levas%n", additionalMinutes, priceForAdditionalMinutes);
 
 
            additionalTaxesPaid = ((additionalMinutes * minuteCost) / 100) * 20;
            System.out.printf("%.2f additional taxes%n", additionalTaxesPaid);
 
            finalPrice = 12 + +priceForAdditionalMinutes + additionalTaxesPaid;
            System.out.printf("%.2f total bill", finalPrice);
        } else {
            System.out.println("0 additional messages for 0.00 levas");
            System.out.println("0 additional minutes for 0.00 levas");
            System.out.println("0.00 additional taxes");
            System.out.println("12.00 total bill");
        }
 
    }
}
1 Like