turt2live

Untitled

Mar 6th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package milk;
  7.  
  8. import java.util.Scanner;
  9.  
  10. public class Main {
  11.     static Scanner console = new Scanner(System.in);
  12.  
  13.     public static void main(String[] args){
  14.         int milkLitres;
  15.         int milkCartonsNeeded;
  16.         double milkCartonsCost;
  17.         double milkCartonsProfit;
  18.  
  19.         System.out.println("Enter how many litres of milk: ");
  20.         // Step A
  21.         milkLitres = console.nextInt();
  22.         // Step B NOTE: How do you round?
  23.         milkCartonsNeeded = (int) Math.ceil((milkLitres / 2.78)); // T2L: Get "highest" number, eg: 2.4 -> 3
  24.         System.out.println("That'll take " + milkCartonsNeeded + " cartons!");
  25.         // Step C
  26.         milkCartonsCost = milkLitres * 0.38;
  27.         System.out.print("For that many litres, it'll cost you $" + String.format("%.2f", milkCartonsCost) + "!");
  28.         System.out.printf("%.2f", milkCartonsCost); //Debug to test printf
  29.         // Step D
  30.         milkCartonsProfit = milkCartonsNeeded * 0.27;
  31.         System.out.println("With that many cartons you can make a profit of $" + String.format("%.2f", milkCartonsProfit) + "!");
  32.  
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment