In: Computer Science
I am struggling to even get started on this assignment. its a teach yourself kind of situation and I have and no issues up to this point but I just can't wrap my head around it.
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
hey there ! i am done with the code .Please give me a like to appreciate my work and efforts...
here is the code -
package Bank;
/**
*
* @author Aditya kumar
*/
enum ACCOUNT_TYPE
{
CHECKING,SAVINGS;
}
public class Account {
//create five variable
private ACCOUNT_TYPE aType;
private String accountOwner;
private double interestRate;
private double Balance;
//setter and getter methods
public ACCOUNT_TYPE getaType() {
return aType;
}
public void setaType(ACCOUNT_TYPE aType) {
this.aType = aType;
}
public String getAccountOwner() {
return accountOwner;
}
public void setAccountOwner(String accountOwner) {
this.accountOwner = accountOwner;
}
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public double getBalance() {
return Balance;
}
public void setBalance(double Balance) {
this.Balance = Balance;
}
//initialize method to initialize varibales
void initialize(ACCOUNT_TYPE atype,String name,double
interestRate,double balance)
{
//set the value
setaType(atype);
setAccountOwner(name);
setInterestRate(interestRate);
setBalance(balance);
}
//display method
void display()
{
System.out.println(" Account Type : "+aType.name());
System.out.println("Account Owner : "+getAccountOwner());
System.out.println("Interest Rate : "+getInterestRate());
System.out.println("Balance : "+getBalance());
}
//deposit to the account
void deposit(double amount)
{
double bal=getBalance();
setBalance(bal+amount);
System.out.println("Successfull Deposit ! ");
}
//withdraw from account
void withdraw(double amount)
{
//if balance is 0 or amount is greater than balance
if(getBalance()<=0 || amount>getBalance())
{
System.out.println("You don't have enough money to
withdraw");
}
else
{
double bal=getBalance();
setBalance(bal-amount);
System.out.println("Successfully withdraw ! ");
}
}
public static void main(String args[])
{
//two object
Account ac=new Account();
Account ac1=new Account();
//initialize with Savings
ac.initialize(ACCOUNT_TYPE.SAVINGS, "Customer B ", 1.1, 500);
//initialize with Checking
ac1.initialize(ACCOUNT_TYPE.CHECKING, "Customer A ", 1.2,
200);
//display
ac.display();
ac1.display();
//deposit into account
ac.deposit(20);
//withdraw from account
ac.withdraw(60);
//display
ac.display();
}
}
and the snapshot of the output is -
Thank You ! Dont forget to Like !