i am not sure how to add the new bank accounts created to an arraylist.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i am not sure how to add the new bank accounts created to an arraylist.
This is all the code. thank you in advace.
import java.util.List; public interface _BankManager { /** * Creates a new current account and then returns details to user * @param name * @param amount * @param overdraftLimit * @return The value object holding summary details for this account */ public BankAccountOutputVO createNewCurrentAccount(String name, double amount, double overdraftLimit); /** * * @param name * @param amount * @return The value object holding summary details for this account */ public BankAccountOutputVO createNewSavingsAccount(String name, double amount); /** * * @param accountNumber * @param amount * @return The value object holding summary details for this account */ public BankAccountOutputVO makeDeposit(String accountNumber, double amount); /** * * @param accountNumber * @param amount * @return The value object holding summary details for this account */ public BankAccountOutputVO makeWithdrawal(String accountNumber, double amount); /** * * @return The list of all accounts currently held in the bank. This list * must consist of objects of type BankAccountOutputVO. */ public List<BankAccountOutputVO> listAllAccounts(); /** * * @param accountNumber * @return The value object holding summary details for this account */ public BankAccountOutputVO ViewAccountSummary(String accountNumber); /** * * @param accountNumber * @return The value object holding summary details for this account */ public BankAccountOutputVO closeAcount(String accountNumber); }public class BankAccount { int accountNumber; String name; double amount; static double balance; double overdraftLimit; boolean successfulTransaction; private final int FIRST = 100; // The first num to generate protected int current = FIRST; // Value at head of sequence public boolean deposit(double amount) { if(amount >= 0.0) { BankAccount.balance += amount; return true; } else return false; } public boolean widthdraw(double amount) { if(amount >= 0 && amount <= balance) { BankAccount.balance -= amount; return true; } else return false; } public void setSuccessfulTransaction(boolean successfulTransaction) { this.successfulTransaction = successfulTransaction; } public boolean isSuccessfulTransaction() { return successfulTransaction; } public String getName() { return name; } public double getBalance() { return balance; } public void setBalance(double balance) { BankAccount.balance = balance; } public int getAccountNumber(){ return accountNumber; } public double getAmount() { return amount; } public String getAccountType() { return "Account"; } public double getOverdraft() { return overdraftLimit; } }
public final class BankAccountOutputVO { private final String accountNumber; private final String accountType; private final String name; private final String balance; private final String overdraft; private final boolean successfulTransaction; public BankAccountOutputVO(String accountNumber, String accountType, String name, String overdraft, String balance, boolean successfulTransaction) { this.accountNumber = accountNumber; this.accountType = accountType; this.name = name; this.overdraft = overdraft; this.balance = balance; this.successfulTransaction = successfulTransaction; } public boolean isSuccessfulTransaction() { return successfulTransaction; } public String getAccountNumber() { return accountNumber; } public String getBalance() { return balance; } public String getName() { return name; } public String getAccountType() { return accountType; } public String getOverdraft() { return overdraft; } }
public final class BankAccountOutputVO { private final String accountNumber; private final String accountType; private final String name; private final String balance; private final String overdraft; private final boolean successfulTransaction; public BankAccountOutputVO(String accountNumber, String accountType, String name, String overdraft, String balance, boolean successfulTransaction) { this.accountNumber = accountNumber; this.accountType = accountType; this.name = name; this.overdraft = overdraft; this.balance = balance; this.successfulTransaction = successfulTransaction; } public boolean isSuccessfulTransaction() { return successfulTransaction; } public String getAccountNumber() { return accountNumber; } public String getBalance() { return balance; } public String getName() { return name; } public String getAccountType() { return accountType; } public String getOverdraft() { return overdraft; } }
public class CurrentAccount extends BankAccount { public CurrentAccount(String name, double amount, double overdraftLimit) { this.name = name; this.amount = amount; this.overdraftLimit = overdraftLimit; this.accountNumber = current++; } public double getOverdraft() { return overdraftLimit; } @Override public boolean widthdraw(double amount) { if (amount >= 0 && amount <= balance + overdraftLimit) { CurrentAccount.balance -= amount; return true; } else return false; } public void withdrawal(double amount) { System.out.println("Your Balance is" + balance); if (amount <= (balance + overdraftLimit)) balance -= amount; else System.out.println("Not enough money in account."); } public void closeAcc(double amount){ System.out.println("The amount requested is " + amount); } @Override public String getAccountType() { return "CurrentAccount"; } }
public class SavingAccount extends BankAccount { public SavingAccount(String name, double amount, double overdraftLimit) { this.name = name; this.amount = amount; this.overdraftLimit = overdraftLimit; this.accountNumber = current++; } public SavingAccount(String accountNumber, double amount) { this.accountNumber = current++; this.amount = amount; } public String getAccountType() { return "SavingAccount"; } // @Override // public void displayAccountName() { // // System.out.println("This is SavingsAccount"); // // } @Override public boolean widthdraw(double amount) { if (amount >= 0 && amount <= balance) { SavingAccount.balance -= amount; return true; } else return false; } @Override public double getOverdraft() { return 0.00; } }
public class SequenceGenerator { private static int FIRST = 100; // The first num to generate private static int current = FIRST; // Value at head of sequence public static synchronized int getNum() { return ++current; } }
import java.util.ArrayList; public class Storage { private ArrayList<Integer> CurrentAccount = new ArrayList<Integer>(); public void add(int number) { CurrentAccount.add(number); } public ArrayList<Integer> getList() { return CurrentAccount; } }
i am also not sure how to implement the withdrawl and deposit functions.
hello, the code of the class BankManager is missing. can you post also this class? other question: the class BankAccount is ok butcould you please explain why you declare another one named BankAccountOutputVO? and since the balance variable in the class BankAccount is static, all instances of BankAccount will share the same value for balance.
Last edited by j2me64; August 11th, 2010 at 08:36 AM.
What's the point of having this method?
public String getAccountType() { return "SavingAccount"; }
Hi sorry for the delay. The BankMangeroutVO class was given to me as part of the package. also the static should be removed as this is an error. Thank you in advance for all your help.
package com.fdm.bank; import java.util.ArrayList; import java.util.List; public class BankManager implements _BankManager { public BankAccountOutputVO ViewAccountSummary(String accountNumber) { // TODO Auto-generated method stub return null; } public BankAccountOutputVO closeAcount(String accountNumber) { // TODO Auto-generated method stub return null; } public BankAccountOutputVO createNewCurrentAccount(String name, double amount, double overdraftLimit) { // long accNumber = BankAccount.randomAccNo(); CurrentAccount currentAcc = new CurrentAccount(name, amount, overdraftLimit); BankAccountOutputVO bao = new BankAccountOutputVO(currentAcc .getAccountNumber() + "", currentAcc.getAccountType(), currentAcc.getName(), currentAcc.getOverdraft() + "", currentAcc.getAmount() + "", true); return bao; } public BankAccountOutputVO createNewSavingsAccount(String name, double amount) { SavingAccount savingAcc = new SavingAccount(name, amount, amount); BankAccountOutputVO bao = new BankAccountOutputVO(savingAcc .getAccountNumber() + "", savingAcc.getAccountType(), savingAcc.getName(), savingAcc.getOverdraft() + "", savingAcc.getAmount() + "", true); return bao; } public List<BankAccountOutputVO> listAllAccounts() { Storage BankAccount = Storage(); ArrayList<Integer> list = BankAccount.getList(); for (Integer counter : list) { System.out.println(counter); } return null; } public BankAccountOutputVO makeDeposit(String accountNumber, double amount) { // TODO Auto-generated method stub return null; } public BankAccountOutputVO makeWithdrawal(String accountNumber, double amount) { // BankAccount BankAcc = new BankAccount(); return null; } }
Oh... ok. So what do you need help with now?
basically i need to create an array list that will read the information from the command line. so the new accounts i create will be add to the array list. hope that make sense thank you for all you help.
What parts are you having problems with? Here's a list of what you asked:
Create an array list
read info from the command line
create new accounts with info from command line
add new accounts to array list
i have managed to create an array list
i am not sure how to add a new account to the arraylist from the command line.
basically i know we have to do this to create a new array but i am not sure how to impement this so it reads the new aacount from the command line
ArrayList<String> myArr = new ArrayList<String>();
myArr.add("Italian Riviera");
myArr.add("Jersey Shore");
myArr.add("Puerto Rico");
You need to create a new account object that holds the customer info and add that to the arraylist.
Did you see the steps I listed in my last post?
Can you show what to do each step?
Create an array list
read info from the command line
create new account object with info from command line
add new account object to array list
public List<BankAccountOutputVO> listAllAccounts() { Storage store = new Storage(); ArrayList<BankAccountOutputVO> bao = new ArrayList<BankAccountOutputVO>(); for (BankAccount acc : store.getList()){ bao.add (Bank.createBAO (acc)); } return bao; }
i have managed to implement the list but there is not being displayed in the list. this is even when i create a new account.
Last edited by Newtojava; August 18th, 2010 at 06:38 AM.
Can you show the output and the code that generates it?but there is not being displayed in the list.
What you posted doesn't "display" anything. It copies some objects into an array list.
Newtojava (August 20th, 2010)
i have manged to sort that out i was using the worng class. thank you.
on of the last few problems are that i am trying to implement the withdrawl function.
public BankAccountOutputVO makeWithdrawal(String accountNumber, double amount) { // BankAccount BA = new BankAccount(); // BA.widthdraw(amount); return null; }
These are the withdrawl function i have got
Last edited by Newtojava; August 18th, 2010 at 10:39 AM.
How does the command line do anything? The 'command line' is a mode of doing I/O with a program. The user types his input into a command line prompt and the program writes its output to the same screen.the command line say the account is closed but the account is not closed
The closeAccount creates a new BankAccount object. What is this used for?
And the same with BankAccountOutputVO
Could you explain the logic of the closeAccount method line by line? I have no idea what your code is supposed to do.
sorry but i made an typing error.
Ok, is it working now?
Newtojava (August 20th, 2010)
I just need to know how to implement the withdrawl function. please.
Last edited by Newtojava; August 19th, 2010 at 03:09 AM.
Can you define what a withdrawal does?
Then describe the steps your method should take to do that.
What is the problem with the one you posted in post#42?
Newtojava (August 20th, 2010)
I have managed to impleament the withdrawl method if was not calling the constutor to call the method.
No more questions then?
Newtojava (August 20th, 2010)
for me the usage of the classes in these application is obscure. i don't know if i'm up-to-date with the code in each class, but suppose i have to run a bank that offers saving and current accounts to customers. as a java developer, where do i have to start with the existing classes?