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