13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

290Chapter 12Analysis and Design: Seeking the ObjectsExample 12.1 The Account classpackage net.multitool.core;import net.multitool.util.*;import java.util.*;import java.sql.*;public classAccount{private String name;// A name to identify this accountprivate User owner;// The user assigned to this accountprivate SAM<strong>on</strong>ey total;// Total amt originally allocated to// this accountprivate SAM<strong>on</strong>ey balance;// amt remaining unallocated to any// subaccountsprivate Account parent;// The account which c<strong>on</strong>tains this// account as a childprivate HashMap children;// The collecti<strong>on</strong> of subaccounts,// by nameprivate static C<strong>on</strong>necti<strong>on</strong> dbC<strong>on</strong>n = null; // JDBC c<strong>on</strong>necti<strong>on</strong>private ArrayList payments;// TODO: unimplementedprivate SAM<strong>on</strong>ey unspent;// TODO: unimplemented/*** Create an account, with a pool of dollars to budget.* Use this c<strong>on</strong>structor to create the master account.* Use createSub to create children of this account.*/publicAccount(String name, User owner, String total)throws NumberFormatExcepti<strong>on</strong>{this.name = name;this.owner = owner;this.total = new SAM<strong>on</strong>ey(Double.valueOf(total).doubleValue());this.balance = new SAM<strong>on</strong>ey(Double.valueOf(total).doubleValue());// N.B. must not be the same objectthis.parent = null;this.children = new HashMap();}// Static that c<strong>on</strong>nects to the DB and either returns the top account,// or creates it for us.public static Account getTopAccount() throws SQLExcepti<strong>on</strong> {Account topAccount = null;dbC<strong>on</strong>n = DriverManager.getC<strong>on</strong>necti<strong>on</strong>("jdbc:postgresql:budgetPro?user=mschwarz");

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!