Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.Console;
- public class MetricConvert {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double magnoliaPrice = 3.25;
- double hyacinthsPrice = 4; // В случая не е от значение, но е по-логично да е от тип double
- double rosesPrice = 3.5;
- double cactusPrice = 8; // В случая не е от значение, но е по-логично да е от тип double
- int magnoliaCount = Integer.parseInt(scan.nextLine());
- int hyacinthsCount = Integer.parseInt(scan.nextLine());
- int rosesCount = Integer.parseInt(scan.nextLine());
- int cactusCount = Integer.parseInt(scan.nextLine());
- double giftPrice = Double.parseDouble(scan.nextLine()); //Тябва да е "Double.parseDouble", иначе все едно четем цяло число.
- double totalPrice = magnoliaCount * magnoliaPrice + hyacinthsCount * hyacinthsPrice + rosesCount * rosesPrice +
- cactusCount * cactusPrice;
- totalPrice *= 0.95; // Смятаме колко пари е спечелила след данъците. Може да се напише и totalPrice = totalPrice - totalPrice * 5 / 100
- //System.out.printf("%s missed a penalty.%n",name);
- if (totalPrice >= giftPrice) {
- System.out.println("She is left with " + (int)Math.floor(totalPrice - giftPrice) + " leva."); // Може да се принтира по този начин. Закръгляме надолу и с (int) го правим цяло число.
- } else {
- System.out.printf("She will have to borrow " + (int)Math.ceil(giftPrice - totalPrice) + " leva."); // Тук се закръгля нагоре. Виж условието
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement