Results 1 to 4 of 4
  1. #1
    ostkanten is offline Member
    Join Date
    Jul 2012
    Posts
    37
    Rep Power
    0

    Default Problem to get accountNumber

    In a class Logic I create SavingAccounts

    Java Code:
    private ArrayList<Account>accounts;
    
    public void addSavingAccount(int accountNumber, double startingBalance, String kontoTyp, String pNumber) {
    		accounts.add(new SavingAccounts(accountNumber, startingBalance, kontoTyp, pNumber));
    	}
    
    ...
    
    public ArrayList<Account> getAllAccounts(int acountNumber, double StartingBalance, String kontoTyp, String PNumber){
    		return accounts;
    	}
    In a class GUI I collect the accounts in a JList.

    Java Code:
    private JList konton;
    I also ask for a selected accountNumber

    Java Code:
    selectedAccountNr = Integer.parseInt(accountNrField.getText());
    When it comes to depositMoney the problem occurs when I compare the selectedAccountNumber with the accountNumbers int he JList. In the AccountClass where the accounts´accountNumber are autogenerated I have a getter

    Java Code:
    public int getAccountNumber(){
    	return this.accountNumber;
    }
    My depositMoney method:

    Java Code:
    private void depositMoney(int selectedAccountNr){
    		int position = kunder.getSelectedIndex();
    		amountIn = Integer.parseInt(getDepositField().getText());
    		for(int j=0; j< konton.getModel().getSize(); j++){
    			if(selectedAccountNr== getAccountNumber(){  // Here I need to write some magic!
    				Object item = konton.getModel().getElementAt(j);  	
    				depositAmount(selectedAccountNr, amountIn);
    				displayJTextArea.setText("");
    				displayJTextArea.setText("Deposit " + amountIn + " kronor.\n" + konto.toString();
    				displayJTextArea.append("\nAccount:  " + (j+1) + item + " \n");
    			}
    			else if (selectedAccountNr!=konto.accountNumber){
    				b=false;
    				testKonto(b);
    			}
    		}
    	}
    Is it possible to tell me what to write instead of getAccountNumber which doesn´t work?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,762
    Rep Power
    25

    Default Re: Problem to get accountNumber

    what to write instead of getAccountNumber which doesn´t work?
    Can you explain what "doesn't work" means?

    What is the method you want to change supposed to do?
    Where is the data it is supposed to return?

    Or are you asking how to code an if() statement?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    ostkanten is offline Member
    Join Date
    Jul 2012
    Posts
    37
    Rep Power
    0

    Default Re: Problem to get accountNumber

    I know how to write an if() statement but I don´t know how to get the account with the right accountNumber from the arraylist. Maybe I need to use a search method?
    Last edited by ostkanten; 09-19-2012 at 08:22 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,762
    Rep Power
    25

    Default Re: Problem to get accountNumber

    Yes, it sounds like you need a search that goes through the accounts in the arraylist looking for the one with the desired accountnumber.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Problems getting an unique accountNumber
    By ostkanten in forum New To Java
    Replies: 11
    Last Post: 08-14-2012, 01:08 PM
  2. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 04:43 AM
  3. Replies: 9
    Last Post: 09-21-2010, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •