In: Computer Science
Account Type: SAVING
Account Owner: Customer B
Interest Rate: 1.1
Balance: 500.0
Account Type: CHECKING
Account Owner: Customer A
Interest Rate: 1.2
Balance: 200.0
Cannot withdraw more than account balance
Account Type: SAVING
Account Owner: Customer B
Interest Rate: 1.1
Balance: 700.0
Account Type: CHECKING
Account Owner: Customer A
Interest Rate: 1.2
Balance: 200.0
enum ACCOUNT_TYPE
{
CHECKING,SAVING
}
class Account
{
private ACCOUNT_TYPE aType;
private String accountOwner;
private double interestRate;
private double balance;
public void setAType(ACCOUNT_TYPE aType)
{
this.aType=aType;
}
public ACCOUNT_TYPE getAType()
{
return aType;
}
public void setAccountOwner(String accountOwner)
{
this.accountOwner=accountOwner;
}
public String getAccountOwner()
{
return accountOwner;
}
public void setInterestrate(double interestRate)
{
this.interestRate=interestRate;
}
public double getInterestRate()
{
return interestRate;
}
public void setBalance(double balance)
{
this.balance=balance;
}
public double getBalance()
{
return balance;
}
public void initialize(ACCOUNT_TYPE aType,String
accountOwner,double interestRate,double balance)
{
this.aType=aType;
this.accountOwner=accountOwner;
this.interestRate=interestRate;
this.balance=balance;
}
public void display()
{
System.out.println("Account Type: "+getAType());
System.out.println("Account Owner: "+getAccountOwner());
System.out.println("Interest Rate: "+getInterestRate());
System.out.println("Balance: "+getBalance());
}
public void deposit(double amount)
{
balance+=amount;
}
public void withdraw(double amount)
{
if(amount>balance)
System.out.println("Cannot withdraw more than account
balance");
else
balance=balance-amount;
}
}
public class Main
{
public static void main(String[] args)
{
Account a1 = new Account();
a1.setAType(ACCOUNT_TYPE.SAVING);
a1.setAccountOwner("Customer
B");
a1.setInterestrate(1.1);
a1.setBalance(500);
Account a2 = new Account();
a2.setAType(ACCOUNT_TYPE.CHECKING);
a2.setAccountOwner("Customer
A");
a2.setInterestrate(1.2);
a2.setBalance(200);
a1.display();
a2.display();
a1.deposit(200);
a2.withdraw(500);
a1.display();
a2.display();
}
}