Advertisement
EntropyStarRover

Untitled

May 1st, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by entropy on 5/1/2017.
  5.  */
  6. public class cakes {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner (System.in);
  9.  
  10. //        The number n – amount of cakes Ivancho wants.
  11. //• The number c – kilograms of flour needed to make one cake.
  12. //• The number f – kilograms of flour available.
  13. //• The number t – amount of truffles available.
  14. //• The number p – price of one truffle.
  15.  
  16.         int cakesWanted=Integer.parseInt(scanner.nextLine());
  17.         double flourNeededPerCake=Double.parseDouble(scanner.nextLine());
  18.         int kgFloorAvailable=Integer.parseInt(scanner.nextLine());
  19.         int trufflesAvailable=Integer.parseInt(scanner.nextLine());
  20.         int trufflePrice=Integer.parseInt(scanner.nextLine());
  21.  
  22.         double maxFlour=cakesWanted*flourNeededPerCake;
  23.  
  24.         //if flour is not enough
  25.         if (maxFlour>kgFloorAvailable){
  26.  
  27.             double numberOfCakes=kgFloorAvailable/flourNeededPerCake;
  28.             double diffFlour=flourNeededPerCake*cakesWanted-kgFloorAvailable;
  29.  
  30.             System.out.print("Can make only "+(int)numberOfCakes+" cakes, need ");
  31.             System.out.printf("%.2f",diffFlour);
  32.             System.out.println(" kg more flour");
  33.  
  34.             //if floor is enough
  35.         } else{
  36.  
  37.             double productionCost=trufflesAvailable*trufflePrice;
  38.             double cakePrice=(productionCost/cakesWanted)*1.25;
  39.  
  40.             System.out.print("All products available, price of a cake: ");
  41.             System.out.printf("%.2f",cakePrice);
  42.  
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement