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

    Default Account information problem

    This withdrawl-method withdraw money and show correct result, but the loop give information that the "chosen account doesn´t exist" for every other account besides the chosen account. I think it is some curly bracket problem but I don´t know how to solve it.

    Java Code:
    public void withdrawMoney(String kundNummer, int kontoNummer){
    		DecimalFormat ranta = new DecimalFormat("0.00");
    		System.out.println("How much do you want to withdraw: ");
    		int amountOut = scanner.nextInt();
    		scanner.nextLine();
    		for(Account konto: accounts){
    			if(kontoNummer==konto.accountNumber){
    				System.out.println("Starting balance: " + ranta.format(konto.getBalance()));	
    				
    				// if it is a SavingAccount
    				if(konto.getKontoTyp().equals("savingaccount")){
    					konto.withdrawAmount(kontoNummer, amountOut);
    					System.out.println("Withdrawel: " + amountOut + " kronor");
    					System.out.println(konto.toString());
    				}
    			}
    				// if it is a CreditAccount
    				if(konto.getKontoTyp().equals("creditaccount")){
    						konto.withdrawAmount(kontoNummer, amountOut);	
    						konto.countInterest(kontoNummer, konto.getInterestRate());
    						System.out.println("Withdrawel: " + amountOut + " kronor");
    						System.out.println(konto.toString());	
    				}
    			else if (kontoNummer !=konto.accountNumber){
    				System.out.println("Chosen account doesn´t exist.");
    			}
    			}
    		}

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,450
    Rep Power
    25

    Default Re: Account information problem

    Do you want to be told about every account that does not match the requested account? That's what the posted code does.

    Or do you want to be told one time that the account does not exist? Move the printing of the message outside the loop and use an if statement to print the message IF the account was not found in the loop. Use a boolean to remember if the account was found in the loop.
    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

Similar Threads

  1. Replies: 1
    Last Post: 08-02-2012, 03:01 AM
  2. Replies: 2
    Last Post: 07-26-2011, 07:48 AM
  3. java bank account problem
    By awil121 in forum New To Java
    Replies: 1
    Last Post: 10-13-2010, 10:47 PM
  4. Transfer from one account to another
    By vividcooper in forum New To Java
    Replies: 3
    Last Post: 01-26-2010, 10:43 PM
  5. Account mix problem
    By nihongbin in forum Threads and Synchronization
    Replies: 3
    Last Post: 12-10-2008, 05:05 AM

Posting Permissions

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