Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 132,641 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,091 people online right now. Registration is fast and FREE... Join Now!




Bankaccount transferring money...need help

 
Reply to this topicStart new topic

Bankaccount transferring money...need help

Shin
post 12 Oct, 2008 - 10:03 AM
Post #1


New D.I.C Head

*
Joined: 12 Oct, 2008
Posts: 6


My Contributions


Hi there..



in my program i had to make 2 seperate bankaccounts and deposit money on the first one
then select any amount of money from the first one and transfer that amount of money to the second one.
ofcourse here we only select an amount of money that is on the first account.it all works fine except when i enter a amount greater then the amount of money on the first account. it has to supossedly say that you cant transfer.

well, i have some code..and i really dont know where i go wrong hope u guys can help me.

CODE


import java.util.*;
public class Opdracht4_5
{

        public static void main(String[] args)
        {
        Scanner sc = new Scanner(System.in);

        
        BankAccount account1 = new BankAccount("1933151","Pietje");
        BankAccount account2 = new BankAccount("9234134","Sjaak");
        account1.deposit(500);
        drukAf(account1,account2);
        
        System.out.println( "choose the amount of money you want to transfer");
        double bedrag= EasyScanner.nextDouble();

    
        transfer(account1,account2, bedrag);
      
        }
        public static void drukAf(BankAccount account1, BankAccount account2)
        {
            System.out.println("gegevens rekening 1<Bankaccount(nummer: "+account1.getAccountNumber()+", naam: "+ account1.getAccountName()+", saldo: "+ account1.getBalance()+")>");
            System.out.println("gegevens rekening 2<Bankaccount(nummer: "+account2.getAccountNumber()+", naam: "+ account2.getAccountName()+", saldo: "+ account2.getBalance()+")>");
            System.out.println();
        }

           public static boolean transfer(BankAccount account1, BankAccount account2, double bedrag)
        {

            if ( bedrag > account1.getBalance())
             System.out.println("Cant Transfer");

             else
            account1.withdraw(bedrag);
            account2.deposit(bedrag);
            
            System.out.println("gegevens rekening 1<Bankaccount(nummer: "+account1.getAccountNumber()+", naam: "+ account1.getAccountName()+", saldo: "+ account1.getBalance()+")>");
            System.out.println("gegevens rekening 2<Bankaccount(nummer: "+account2.getAccountNumber()+", naam: "+ account2.getAccountName()+", saldo: "+ account2.getBalance()+")>");

          return true;
        }

}
User is offlineProfile CardPM

Go to the top of the page

pbl
post 12 Oct, 2008 - 10:08 AM
Post #2


D.I.C Lover

Group Icon
Joined: 6 Mar, 2008
Posts: 2,982



Thanked 190 times

Dream Kudos: 75
My Contributions


you have {} missing for your else

CODE

            else  {
            account1.withdraw(bedrag);
            account2.deposit(bedrag);
           }

User is offlineProfile CardPM

Go to the top of the page

Shin
post 12 Oct, 2008 - 10:11 AM
Post #3


New D.I.C Head

*
Joined: 12 Oct, 2008
Posts: 6


My Contributions


hahaha ur the best thx
User is offlineProfile CardPM

Go to the top of the page

Gloin
post 12 Oct, 2008 - 01:11 PM
Post #4


On MeD.i.Cation

Group Icon
Joined: 4 Aug, 2008
Posts: 717



Thanked 46 times
My Contributions


Also, since you don't really return anything, your method could return void instead of boolean. although returning false might also be an option when your if-statement evaluates true.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 04:35AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month