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.

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 51

Thread: Help with programe please

  1. #26
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    i am not sure how to add the new bank accounts created to an arraylist.

  2. #27
    Member
    Join Date
    May 2010
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 12 Posts

    Default Re: Help with programe please

    Quote Originally Posted by Newtojava View Post
    i am not sure how to add the new bank accounts created to an arraylist.

    if you post all your code i may help you. because till now when i try to compile your code i got several conceptional errors.

  3. #28
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    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;
    	}
     
    }

  4. #29
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    i am also not sure how to implement the withdrawl and deposit functions.

  5. #30
    Member
    Join Date
    May 2010
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 12 Posts

    Default Re: Help with programe please

    Quote Originally Posted by Newtojava View Post
    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.

  6. #31
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Help with programe please

    What's the point of having this method?
      public String getAccountType() {
            return "SavingAccount";
        }

  7. #32
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    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;
    	}
     
    }

  8. #33
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    Quote Originally Posted by Brt93yoda View Post
    What's the point of having this method?
      public String getAccountType() {
            return "SavingAccount";
        }
    This is for the reason that we have two account types one is saving the other is current.

  9. #34
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Help with programe please

    Oh... ok. So what do you need help with now?

  10. #35
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    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.

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,075
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Help with programe please

    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

  12. #37
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    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");

  13. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,075
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Help with programe please

    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

  14. #39
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: Help with programe please

    Quote Originally Posted by aussiemcgr View Post
    (I'm going to use * to represent [ and ] since I dont know how to stop parsing) *highlight=java* and this after your code */highlight*. And your code will look nice and colorful.
    Hmmm...

    [highlight=java] ** code goes here ** [/highlight]

    Quote this post to see how it's done.

    db

  15. #40
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

     
    		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.

  16. #41
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,075
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Help with programe please

    but there is not being displayed in the list.
    Can you show the output and the code that generates it?
    What you posted doesn't "display" anything. It copies some objects into an array list.

  17. The Following User Says Thank You to Norm For This Useful Post:

    Newtojava (August 20th, 2010)

  18. #42
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    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

    public void widthdraw(double amount) {
    		if (amount >= 0 && amount <= balance) {
    			balance = balance - amount;
    			System.out.println("you have have cosen to withdraw " + amount);
    		} else {
    			System.out.println("Please enter an amount");
    		}
     
    	}
    Last edited by Newtojava; August 18th, 2010 at 10:39 AM.

  19. #43
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,075
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Help with programe please

    the command line say the account is closed but the account is not closed
    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 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.

  20. #44
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    sorry but i made an typing error.

  21. #45
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,075
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Help with programe please

    Ok, is it working now?

  22. The Following User Says Thank You to Norm For This Useful Post:

    Newtojava (August 20th, 2010)

  23. #46
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    I just need to know how to implement the withdrawl function. please.
    Last edited by Newtojava; August 19th, 2010 at 03:09 AM.

  24. #47
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,075
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Help with programe please

    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?

  25. The Following User Says Thank You to Norm For This Useful Post:

    Newtojava (August 20th, 2010)

  26. #48
    Junior Member
    Join Date
    Aug 2010
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help with programe please

    I have managed to impleament the withdrawl method if was not calling the constutor to call the method.

  27. #49
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,075
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Help with programe please

    No more questions then?

  28. The Following User Says Thank You to Norm For This Useful Post:

    Newtojava (August 20th, 2010)

  29. #50
    Member
    Join Date
    May 2010
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 12 Posts

    Default Re: Help with programe please

    Quote Originally Posted by Norm View Post
    No more questions then?
    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?

Page 2 of 3 FirstFirst 123 LastLast