Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //1. входни данни
- int countMagnolias = Integer.parseInt(scanner.nextLine()); //брой на магнолиите
- int countHyacinths = Integer.parseInt(scanner.nextLine()); //брой на зюмбюлите
- int countRoses = Integer.parseInt(scanner.nextLine()); //брой на розите
- int countCacti = Integer.parseInt(scanner.nextLine()); //брой на кактусите
- double priceGift = Double.parseDouble(scanner.nextLine()); //цена на подарък, който трябва да купи
- //2. обща сума = сума от магнолиите + сума от зюмбюлите + сума от рози + сума от кактуси
- double totalPrice = (countMagnolias * 3.25)
- + (countHyacinths * 4)
- + (countRoses * 3.50)
- + (countCacti * 8);
- //3. данъци = 5% от обща сума
- double taxes = 0.05 * totalPrice;
- //4. печалба = обща сума - данъци
- double profit = totalPrice - taxes;
- //проверка дали е стигнала печалбата
- if (profit >= priceGift) {
- //достатъчна
- double leftMoney = profit - priceGift;
- System.out.printf("She is left with %.0f leva.", Math.floor(leftMoney));
- } else {
- //недостатъчна -> profit < priceGift
- double needMoney = priceGift - profit;
- System.out.printf("She will have to borrow %.0f leva.", Math.ceil(needMoney));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement