Advertisement
knoteva

Untitled

Nov 2nd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.Console;
  3. public class MetricConvert {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         double magnoliaPrice = 3.25;
  7.         double hyacinthsPrice = 4; // В случая не е от значение, но е по-логично да е от тип double
  8.         double rosesPrice = 3.5;
  9.         double cactusPrice = 8; // В случая не е от значение, но е по-логично да е от тип double
  10.  
  11.         int magnoliaCount = Integer.parseInt(scan.nextLine());
  12.         int hyacinthsCount = Integer.parseInt(scan.nextLine());
  13.         int rosesCount = Integer.parseInt(scan.nextLine());
  14.         int cactusCount = Integer.parseInt(scan.nextLine());
  15.         double giftPrice = Double.parseDouble(scan.nextLine()); //Тябва да е "Double.parseDouble", иначе все едно четем цяло число.
  16.  
  17.         double totalPrice = magnoliaCount * magnoliaPrice + hyacinthsCount * hyacinthsPrice +  rosesCount * rosesPrice +
  18.                 cactusCount * cactusPrice;
  19.  
  20.         totalPrice *= 0.95; // Смятаме колко пари е спечелила след данъците. Може да се напише и   totalPrice = totalPrice - totalPrice * 5 / 100
  21.         //System.out.printf("%s missed a penalty.%n",name);
  22.         if (totalPrice >= giftPrice) {
  23.             System.out.println("She is left with " + (int)Math.floor(totalPrice - giftPrice) + " leva."); // Може да се принтира по този начин. Закръгляме надолу и с (int) го правим цяло число.
  24.         } else {
  25.             System.out.printf("She will have to borrow " + (int)Math.ceil(giftPrice - totalPrice) + " leva."); // Тук се закръгля нагоре. Виж условието
  26.         }
  27.  
  28.  
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement