import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner;

/**
 * Prompts the user for coin counts and outputs the total in dollars and cents. Four 
 * different ways of formatting the cents as a two-digit number are shown.
 * 
 * @author Drue Coles
 */
public class NumberFormattingDemo2 {
    
    public static void main(String[] args) {
        
        System.out.print("Enter number of quarters, dimes, nickels, and pennies: ");
        Scanner in = new Scanner(System.in);
        int q = in.nextInt();
        int d = in.nextInt();
        int n = in.nextInt();
        int p = in.nextInt();
        
        int total = 25 * q + 10 * d + 5 * n + p;
        int dollars = total / 100;
        int cents = total % 100;
        
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumIntegerDigits(2);
        System.out.println("Total = $" + dollars + "." + nf.format(cents));
        
        // Alternative way to format cents as a two-digit number.
        DecimalFormat df = new DecimalFormat("00");
        System.out.println("Total = $" + dollars + "." + df.format(cents));
        
        // Alternative way to format cents as a two-digit number.
        System.out.println("Total = $" + dollars + "." + String.format("%02d", cents));
        
        // Alternative way to format cents as a two-digit number.
        System.out.printf("Total = $%d.%02d %n", dollars, cents);         
    }
}