Thursday, December 8, 2011

Java PROS, some help would be appreciated!?

I've been working overnight on this project:





"


We are getting to the good stuff. Now that we have added methods to our arsenal it's time to add classes. Classes allow us to create objects and that's exactly what we are going to do. For this assignment you will create a class Account that will represent a Bank Account. You will also create a class Bank which will hold various Accounts in an array. There will be two types of Accounts: Checking and Savings, and they will operate under different constraints as you will see below. *Hint: Checking and Savings accounts are types of Accounts.





Types of Accounts:


When you create a new Account you should give it the holder's name as well as a starting balance. If one is not given there should be a default value. Any type of Account you create must be able to do the following (in other words must include the following methods)





void setRate (double v) //sets the rate


void deposit (double v)//deposits a given amount into the account


void withDrawal (double v)//subtracts a given amount from the account


void calcInterest ()// calculates yearly interest and adds it to the balance


double getBalance () // that returns the current balance


String toString() // returns a String with all the information of the acct








//CheckAcct: a Checking account only receives interest if balance %26gt; $1000





//SavAcct: A Savings account, can only withdraw up to $200 at a time





The Bank should be able to calculate interest for all the Accounts it holds.


(calcInterestAll) and it should get the total balance in the Bank (totalBalance())


It will also have to have a methods that add Accounts to the Bank.





Your main class should operate as follows:





public class YourNameAss3{





public static void main (String [] args) throws Exception {





Account a = new Account("Donald Duck", 100.00);


CheckAcct chk = new CheckAcct("Scrooge McDuck", 5000.0);


SavAcct sav = new SavAcct("Condoleeza Rice", 320.0);





chk.deposit(100.00);


sav.deposit(100.00);


a.deposit(100.00);





sav.withDrawal(300.0);


chk.withDrawal(200.0);





Bank CIBC = new Bank(10);





a.deposit(100.00);


a.withDrawal(50.00);





System.out.println("Account a : " + a.getBalance() );


System.out.println("Account chk : " + chk.getBalance() );





CIBC.addAcct(a);


CIBC.addAcct(sav);


CIBC.addAcct(new Account("Scrooge McDuck", 1000.00));





System.out.println(a.toString()); //This could be used to get info for //account a or any other account





System.out.println("Total Balance for CIBC : " + CIBC.totalBalance() );


System.in.read(); //This is not necessary in BlueJ


}








}"





I havn't gotten anywhere besides building some of the constructors.





Could any experienced Java programmer show me how this is done?|||CheckAcct and SavAcct should both extend Account, which has all the methods in it





Having private variables in Account for rate and balance





deposit/withdrawal/setRate just change those variables


(something like:


public void deposit (double amount) {


balance += amount;


}


etc)





For the Bank class, you basically just want it to have a private Array to store all the accounts in, and methods calcInterestAll() and totalBalance(), which will just iterate over the contents of the array either calling calcInterest on each one or summing up the balances for output





Don't forget to add a check in your loop iterating over the array of accounts for null values since you're using an array and not an arraylist|||You may contact a java programmer live below.

No comments:

Post a Comment