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 abstract class Transaction {
    public Transaction(long amount) {
        setAmount(amount);
    }

        // Thrown by sub classes.
    public static class InvalidTransactionException extends Exception {
        public InvalidTransactionException(String s){
            super(s);
        }
    }

        // 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 = amountAsString(getAmount());
        return StringFormatter.rightAdjust(amount,getFormatWidth());
    }

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

    public long getAmount(){
        return amount;
    }

    protected void setAmount(long a){
        amount = a;
    }

        // Return amount in the form: "dollars.cents"
    public static String amountAsString(long amount){
        long dollars = amount/100L;
        long cents = amount % 100L;

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

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

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

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