My friend is stuck with this...and the ko4life has lots of programmers (I think) Can you guys help us ?
Much thanks is advance
Friend quote:
I created a class called Bank;
And the corresponding testclass to work with the first class.
But when i run the program it does not do what i want it to do.
i want it to return the deposit amount. And apparently it returns some sort of default value, that is equal to zero.
This is the class Bank:
//create a class called Bank
public class Bank
{
//Declaration of class: field variables
private double balance;
private String account;
public double amount;
public double newBalance;
//build constructor
public Bank(double initialBalance, String AccountNumber)
{
balance=initialBalance;
account=AccountNumber;
}
//mutator methods: operate by redifining a given variable
public void deposit(double amount)//this method needs to add to the balance
{
double newBalance=balance+amount;
balance=newBalance;
}
public void withdraw(double amount)
{
double newBalance=balance-amount;
balance=newBalance;
}
//accessor methods: operate via the return statement
//accessing the balance
public double getBalance()
{
return balance;
}
//accessing the account number
public String getAccountNumber()
{
return account;
}
// need to build the getTransaction method??????
public double getTransaction()
{
return amount;
}
}
This is the testclass:
//create testclass called "TestBank"
class TestBank
{ //create main method:
public static void main(String[] arg)
{ //create new object within the class "Bank" with reference variable "b"
Bank b= new Bank(100,"098-055-9325");
//print line with accessor methods retrieving the information via the return statement
System.out.println("Account: "+b.getAccountNumber()+"\tOpening balance $"+b.getBalance());
//make a deposit
b.deposit(50);
System.out.println("Deposit $"+b.getTransaction()+"\t\tNew balance $"+b.getBalance());
}
}
This is the corresponding output of the program:
Account: 098-055-9325 Opening balance $100.0
Deposit $0.0 New balance $150.0
Once again, i can successfully add the $50,0 to the account and fetch the new balance;
but i cannot fetch correctly the deposit amount.
This is where i am stuck.
Bookmarks