import java.io.*;

        /* Hold an amount of money representing a credit or debit
         * transaction. The amount is a long integer.
         * The toString() method formats the amount in a width
         * determined by getFormatWidth().
         * The printAmount() prints the formatted amount to the
         * specified Writer.
         */

public class Transaction {
    public Transaction(long amount) {
        this.amount = amount;
    }

        // Return the formatted amount as a string.
        // The amount should be right adjusted in a field of
        // the length returned by getFormatWidth().
    public String toString(){
        // Get the formatted version of the amount.
        String amount = formattedAmount();

        // Create a prefix of spaces to fill the remaining format width.
        int prefixLength = getFormatWidth()-amount.length();

        StringBuffer prefix = new StringBuffer();
        for(int i = 0; i < prefixLength; i++){
            prefix.append(" ");
        }
        prefix.append(amount);
        return prefix.toString();
    }

        // Print the amount formatted as a string.
    public void printAmount(Writer writer) throws IOException{
        writer.write(toString());
    }

    public long getAmount(){
        return amount;
    }

    // Return amount in the form: "dollars.cents"
    protected String formattedAmount(){
        long amount = getAmount();
        long dollars = amount/centsPerDollar;
        long cents = amount % centsPerDollar;

        // Make up the result from its components.
        String result = dollars+".";

        // Make sure that the number of cents is always two digits.
        if(cents < 10){
            result += "0"+cents;
        }
        else{
            result += cents;
        }
        return result;
    }

    // Return the width in which to format the amount.
    protected int getFormatWidth(){
        return defaultFormatWidth;
    }

    private static final int centsPerDollar = 100;

    // The default width of the formatted amount.
    private final int defaultFormatWidth = 10;

    // The amount of the credit, debit or transfer.
    private final long amount;
}
