Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package milk;
- import java.util.Scanner;
- public class Main {
- static Scanner console = new Scanner(System.in);
- public static void main(String[] args){
- int milkLitres;
- int milkCartonsNeeded;
- double milkCartonsCost;
- double milkCartonsProfit;
- System.out.println("Enter how many litres of milk: ");
- // Step A
- milkLitres = console.nextInt();
- // Step B NOTE: How do you round?
- milkCartonsNeeded = (int) Math.ceil((milkLitres / 2.78)); // T2L: Get "highest" number, eg: 2.4 -> 3
- System.out.println("That'll take " + milkCartonsNeeded + " cartons!");
- // Step C
- milkCartonsCost = milkLitres * 0.38;
- System.out.print("For that many litres, it'll cost you $" + String.format("%.2f", milkCartonsCost) + "!");
- System.out.printf("%.2f", milkCartonsCost); //Debug to test printf
- // Step D
- milkCartonsProfit = milkCartonsNeeded * 0.27;
- System.out.println("With that many cartons you can make a profit of $" + String.format("%.2f", milkCartonsProfit) + "!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment