Untitled

 avatar
unknown
plain_text
3 years ago
2.5 kB
11
Indexable
import java.util.ArrayList;
import java.util.Objects;

public class Account {
    private static double balance = 0;
    private static ArrayList<Transaction> transitionList = new ArrayList<Transaction>();
    public static int index = 1;

    /**
     *An abstract class that represents an algorithm.
     *
     * @author zhangtj
     *
     * @version 1.0
     */
    private static void deposit(double amount) {
        if (amount <= 0) {
            System.out.println("So tien ban nap vao khong hop le!");
        } else {
            balance += amount;
            transitionList.add(new Transaction("Giao dich " + index
                    + ": Nap tien $%.2f. So du luc nay: $%.2f.\n", amount, balance));
            ++index;
        }
    }

    /**
     *An abstract class that represents an algorithm.
     *
     * @author zhangtj
     *
     * @version 1.0
     */
    private static void withdraw(double amount) {
        if (amount <= 0) {
            System.out.println("So tien ban rut ra khong hop le!");
        } else if (amount > balance) {
            System.out.println("So tien ban rut vuot qua so du!");
        } else {
            balance -= amount;
            transitionList.add(new Transaction("Giao dich " + index
                    + ": Rut tien $%.2f. So du luc nay: $%.2f.\n", amount, balance));
            ++index;
        }
    }

    /**
     *An abstract class that represents an algorithm.
     *
     * @author zhangtj
     *
     * @version 1.0
     */
    public static void addTransaction(double amount, String operation) {
        if (Objects.equals(operation, Transaction.DEPOSIT)) {
            deposit(amount);
        } else if (Objects.equals(operation, Transaction.WITHDRAW)) {
            withdraw(amount);
        } else {
            System.out.println("Yeu cau khong hop le!");
        }
    }

    /**
     *An abstract class that represents an algorithm.
     *
     * @author zhangtj
     *
     * @version 1.0
     */
    public static void printTransaction() {
        for (int i = 0; i < transitionList.size(); i++) {
            System.out.printf(transitionList.get(i).getOperation(),
                    transitionList.get(i).getAmount(), transitionList.get(i).getBalance());
        }
    }

    /**
     *An abstract class that represents an algorithm.
     *
     * @author zhangtj
     *
     * @version 1.0
     */
    public static void main(String[] args) {
        
    }
}
Editor is loading...