<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Need help setting initial balances in Bank Account program.' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Need help setting initial balances in Bank Account program.' posted on the 'Java' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Tue, 18 Jun 2013 17:35:10 -0700</pubDate>
    <lastBuildDate>Tue, 18 Jun 2013 17:35:10 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Need help setting initial balances in Bank Account program.</title>
      <link>http://www.programmersheaven.com/mb/java/419761/419761/need-help-setting-initial-balances-in-bank-account-program/</link>
      <description>&lt;pre class="sourcecode"&gt;//Demonstrates the BankAccount and derived classes

import java.text.*;			// to use Decimal Format

public class AccountDriver
{
	public static void main(String[] args)
	{
		double put_in = 500;
		double take_out = 1000;

		DecimalFormat myFormat;
		String money;
		String money_in;
		String money_out;
		boolean completed;

		// to get 2 decimals every time
		myFormat = new DecimalFormat("#.00");

		//to test the Checking Account class
		CheckingAccount myCheckingAccount =
				new CheckingAccount ("Benjamin Franklin", 1000);
		System.out.println ("Account Number "
			+ myCheckingAccount.getAccountNumber() + 
			" belonging to " + myCheckingAccount.getOwner());
		money  = myFormat.format(myCheckingAccount.getBalance());
		System.out.println ("Initial balance = $" + money);
		myCheckingAccount.deposit (put_in);
		money_in = myFormat.format(put_in);
		money  = myFormat.format(myCheckingAccount.getBalance());
		System.out.println ("After deposit of $" + money_in
			+ ",  balance = $" + money);
		completed = myCheckingAccount.withdraw(take_out);
		money_out = myFormat.format(take_out);
		money  = myFormat.format(myCheckingAccount.getBalance());
		if (completed)
		{
			System.out.println ("After withdrawal of $" + money_out
					+ ",  balance = $" + money);
		}
		else
		{
			System.out.println ("Insuffient funds to withdraw $"
					+ money_out	+ ",  balance = $" + money);
		}
		System.out.println();

		//to test the savings account class
		SavingsAccount yourAccount =
				new SavingsAccount ("William Shakespeare", 400);
		System.out.println ("Account Number "
				+ yourAccount.getAccountNumber() +
				" belonging to " + yourAccount.getOwner());
		money  = myFormat.format(yourAccount.getBalance());
		System.out.println ("Initial balance = $" + money);
		yourAccount.deposit (put_in);
		money_in = myFormat.format(put_in);
		money  = myFormat.format(yourAccount.getBalance());
		System.out.println ("After deposit of $" + money_in
				+ ",  balance = $" + money);
		completed = yourAccount.withdraw(take_out);
		money_out = myFormat.format(take_out);
		money  = myFormat.format(yourAccount.getBalance());
		if (completed)
		{
			System.out.println ("After withdrawal of $" + money_out
				+ ",  balance = $" + money);
		}
		else
		{
			System.out.println ("Insuffient funds to withdraw $"
				+ money_out	+ ",  balance = $" + money);
		}
		yourAccount.postInterest();
		money  = myFormat.format(yourAccount.getBalance());
		System.out.println ("After monthly interest has been posted,"
				+ "balance = $"	+ money);
		System.out.println();


		// to test the copy constructor of the savings account class
		SavingsAccount secondAccount =
				new SavingsAccount (yourAccount,5);
		System.out.println ("Account Number "
				+ secondAccount.getAccountNumber()+
				" belonging to " + secondAccount.getOwner());
		money  = myFormat.format(secondAccount.getBalance());
		System.out.println ("Initial balance = $" + money);
		secondAccount.deposit (put_in);
		money_in = myFormat.format(put_in);
		money  = myFormat.format(secondAccount.getBalance());
		System.out.println ("After deposit of $" + money_in
				+ ", balance = $" + money);
		secondAccount.withdraw(take_out);
		money_out = myFormat.format(take_out);
		money  = myFormat.format(secondAccount.getBalance());
		if (completed)
		{
			System.out.println ("After withdrawal of $" + money_out
					+ ",  balance = $" + money);
		}
		else
		{
			System.out.println ("Insuffient funds to withdraw $"
					+ money_out	+ ",  balance = $" + money);
		}
		System.out.println();

		//to test to make sure new accounts are numbered correctly
		CheckingAccount yourCheckingAccount =
				new CheckingAccount ("Issac Newton", 5000);
		System.out.println ("Account Number "
				+ yourCheckingAccount.getAccountNumber()
				+ " belonging to "
				+ yourCheckingAccount.getOwner());

	}
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;public abstract class BankAccount
{
	// class variable so that each account has a unique number
	protected static int numberOfAccounts = 100001;

	// current balance in the account
	private double balance;
	// name on the account
	private String owner;
	// number bank uses to identify account
	private String accountNumber;

	//default constructor
	public BankAccount()
	{
		balance = 0;
		accountNumber = numberOfAccounts + "";
		numberOfAccounts++;
	}

	//standard constructor
	public BankAccount(String name, double amount)
	{
		owner = name;
		balance = amount;
		accountNumber = numberOfAccounts + "";
		numberOfAccounts++;
	}

	//copy constructor
	public BankAccount(BankAccount oldAccount, double amount)
	{
		owner = oldAccount.owner;
		balance = amount;
		accountNumber = oldAccount.accountNumber;
	}

	//allows you to add money to the account
	public void deposit(double amount)
	{
		balance = balance + amount;
	}

	//allows you to remove money from the account if
	//enough money is available
	//returns true if the transaction was completed
	//returns false if the there was not enough money
	public boolean withdraw(double amount)
	{
		boolean completed = true;

		if (amount &amp;lt;= balance)
		{
			balance = balance - amount;
		}
		else
		{
			completed = false;
		}
		return completed;
	}

	//accessor method to balance
	public double getBalance()
	{
		return balance;
	}

	//accessor method to owner
	public String getOwner()
	{
		return owner;
	}

	//accessor method to account number
	public String getAccountNumber()
	{
		return accountNumber;
	}

	//mutator method to change the balance
	public void setBalance(double newBalance)
	{
		balance = newBalance;
	}

	//mutator method to change the account number
	public void setAccountNumber(String newAccountNumber)
	{
		accountNumber = newAccountNumber;
	}
}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;public class SavingsAccount extends BankAccount
   {
     
	  
	  
	  public SavingsAccount(String string, double rate)
      {
      interestRate = .025; 
      }
      public SavingsAccount(SavingsAccount yourAccount, int rate) {
         
      }
      public void addInterest() 
      {
      double interest = getBalance() * interestRate / 12; 
      deposit(interest); 
      }
      private double interestRate; 

      
   public void postInterest() {
      double balance = getBalance();
      balance += (balance * interestRate);
      deposit(balance);

   }
    
   }

&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;public class CheckingAccount extends BankAccount  {

	 private int transactionCount;

     private static final int FREE_TRANSACTIONS = 0;
     private static final double TRANSACTION_FEE = 0.15;
     
	   public CheckingAccount(String string, double initialBalance)
	{  
	      // Construct superclass
	      super(string, initialBalance);

	      // Initialize transaction count
	      transactionCount = 0; 
	}
	   public void deposit(double amount) 
	{  
	      transactionCount++;
	      // Now add amount to balance 
	      super.deposit(amount); 
	}
	  
	   public boolean withdraw(double amount) 
	{  
	      transactionCount++;
	      return super.withdraw(amount); 
	}
	   public void deductFees()
	{  
	   
	}

	     
	} 
&lt;/pre&gt;&lt;br /&gt;
&lt;strong&gt;&lt;br /&gt;
Expected output:&lt;/strong&gt;&lt;br /&gt;
Account Number 100001-10 belonging to Benjamin Franklin&lt;br /&gt;
Initial balance = $1000.00&lt;br /&gt;
After deposit of $500.00,  balance = $1500.00&lt;br /&gt;
After withdrawal of $1000.00,  balance = $499.85&lt;br /&gt;
&lt;br /&gt;
Account Number 100002-0 belonging to William Shakespeare&lt;br /&gt;
Initial balance = $400.00&lt;br /&gt;
After deposit of $500.00,  balance = $900.00&lt;br /&gt;
Insuffient funds to withdraw $1000.00,  balance = $900.00&lt;br /&gt;
After monthly interest has been posted,balance = $901.88&lt;br /&gt;
&lt;br /&gt;
Account Number 100002-1 belonging to William Shakespeare&lt;br /&gt;
Initial balance = $5.00&lt;br /&gt;
After deposit of $500.00, balance = $505.00&lt;br /&gt;
Insuffient funds to withdraw $1000.00,  balance = $505.00&lt;br /&gt;
&lt;br /&gt;
Account Number 100003-10 belonging to Issac Newton&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Output I am getting:&lt;/strong&gt;&lt;br /&gt;
Account Number 100001 belonging to Benjamin Franklin&lt;br /&gt;
Initial balance = $1000.00&lt;br /&gt;
After deposit of $500.00,  balance = $1500.00&lt;br /&gt;
After withdrawal of $1000.00,  balance = $500.00&lt;br /&gt;
&lt;br /&gt;
Account Number 100002 belonging to null&lt;br /&gt;
Initial balance = $.00&lt;br /&gt;
After deposit of $500.00,  balance = $500.00&lt;br /&gt;
Insuffient funds to withdraw $1000.00,  balance = $500.00&lt;br /&gt;
After monthly interest has been posted,balance = $1012.50&lt;br /&gt;
&lt;br /&gt;
Account Number 100003 belonging to null&lt;br /&gt;
Initial balance = $.00&lt;br /&gt;
After deposit of $500.00, balance = $500.00&lt;br /&gt;
Insuffient funds to withdraw $1000.00,  balance = $500.00&lt;br /&gt;
&lt;br /&gt;
Account Number 100004 belonging to Issac Newton&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/419761/419761/need-help-setting-initial-balances-in-bank-account-program/</guid>
      <pubDate>Wed, 17 Nov 2010 20:41:19 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Need help setting initial balances in Bank Account program.</title>
      <link>http://www.programmersheaven.com/mb/java/419761/430211/re-need-help-setting-initial-balances-in-bank-account-program/#430211</link>
      <description>SavingAcccount need to be change like this.&lt;br /&gt;
&lt;br /&gt;
public class SavingsAccount extends BankAccount&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public SavingsAccount(String string, double rate)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
super(string,rate);&lt;br /&gt;
}&lt;br /&gt;
public SavingsAccount(SavingsAccount yourAccount, int rate) {&lt;br /&gt;
super(yourAccount,rate);&lt;br /&gt;
}&lt;br /&gt;
public void addInterest() &lt;br /&gt;
{&lt;br /&gt;
double interest = getBalance() * interestRate / 12; &lt;br /&gt;
deposit(interest); &lt;br /&gt;
}&lt;br /&gt;
private double interestRate; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public void postInterest() {&lt;br /&gt;
double balance = getBalance();&lt;br /&gt;
balance += (balance * interestRate);&lt;br /&gt;
deposit(balance);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/419761/430211/re-need-help-setting-initial-balances-in-bank-account-program/#430211</guid>
      <pubDate>Sun, 11 Nov 2012 15:36:17 -0700</pubDate>
      <category>Java</category>
    </item>
  </channel>
</rss>