BankAccount Class

class BankAccount
{

double balance; // instance field
string name; // instace field
static double interest; // static field

public BankAccount() // default constructor
{

this(1000, “JAVA17”) ;
}

public BankAccount(double balance, string name)
{

this.balance = balance;
this.name = name;
BankAccount.interest = 0.7; // 0.7%

}

public void deposit(double amount) // instance method
{

balance += amount;

}

public void withdrawal(double amount) // instance method
{

balance -= amount;

}

public void print() // instance method
{

double currentBalance = balance + balance * interest * 0.01;

System.out.printf(“%s의 계좌 잔고는 %f\n”, name, currentBalance);

}

public static void setInterestRate(double interest) // static method
{

BankAccount.interest = interest;

}

}

 

class BankAccountTest {

public static void main(String[] args) {

BankAccount b = new BankAccount(5000, “HCI222222222222”);
b.print();

b.deposit(1000);
b.print();

b.withdrawal(500);
b.print();

BankAccount.setInterestRate(1.5); // 1.5%
b.print();

BankAccount b2 = new BankAccount();
b2.print();

}

}