Java Reference
In-Depth Information
Example 12.1 The Account class
package net.multitool.core;
import net.multitool.util.*;
import java.util.*;
import java.sql.*;
public class
Account
{
private String name; // A name to identify this account
private User owner; // The user assigned to this account
private SAMoney total; // Total amt originally allocated to
// this account
private SAMoney balance; // amt remaining unallocated to any
// subaccounts
private Account parent; // The account which contains this
// account as a child
private HashMap children; // The collection of subaccounts,
// by name
private static Connection dbConn = null; // JDBC connection
private ArrayList payments; // TODO: unimplemented
private SAMoney unspent; // TODO: unimplemented
/**
* Create an account, with a pool of dollars to budget.
* Use this constructor to create the master account.
* Use createSub to create children of this account.
*/
public
Account(String name, User owner, String total)
throws NumberFormatException
{
this.name = name;
this.owner = owner;
this.total = new SAMoney(Double.valueOf(total).doubleValue());
this.balance = new SAMoney(Double.valueOf(total).doubleValue());
// N.B. must not be the same object
this.parent = null;
this.children = new HashMap();
}
// Static that connects to the DB and either returns the top account,
// or creates it for us.
public static Account getTopAccount() throws SQLException {
Account topAccount = null;
dbConn = DriverManager.getConnection("jdbc:postgresql:budgetPro?user=mschwarz");
Search WWH ::




Custom Search