Share

PRELIMCLASS1

Public

09 March 2021

Views: 26

public class Bank{

private String name, surName;
private String address;
private long phoneNum;
private double balance;
private String lastOperationPerformed;

// parameterized constructor to initialize te instance variables
public Bank(String name, String surName, String address, long phoneNum) {
super();
this.name = name;
this.surName = surName;
this.address = address;
this.phoneNum = phoneNum;
this.balance = 0.0;
this.lastOperationPerformed = "No Acction perfomed";
}

public String getName() {
return name;
}
public String getSurName() {
return surName;
}
public String getAddress() {
return address;
}
public long getPhoneNum() {
return phoneNum;
}


public double getBalance() {
return balance;
}
public String getLastOperationPerformed() {
return lastOperationPerformed;
}

public void credit(double amount) {
lastOperationPerformed = "Credit";
this.balance += amount;
System.out.println("New Balance after credit: "+balance);
}

public void withdraw(double amount){
lastOperationPerformed = "Withdraw";

if(amount <= this.balance) {
this.balance -= amount;
System.out.println("Left Balance: "+balance);
}
else {
System.out.println("Insufficient Balance !!");
}
}
}

Advertisement

Disable Third Party Ads