Create your own class named BankAccount that illustrates the use of encapsulation as shown above.
Make sure to include at least one setter and one getter for the class. Add variables and methods
related to a BankAccount class as many as you can.
public class BankAccount {
private int IdNumber;
private int balance;
private int bonuses;
private String ownerName;
private int generateID(int idNumber) {
idNumber = (int) ( Math.random() * 5000 ) + 1000;
return idNumber;
}
public void info(String ownerName, int balance) {
System.out.println("Name of owner - " + ownerName);
System.out.println("Balance: " + balance);
}
public int accrualBonuses(int bonuses) {
bonuses = bonuses + (balance % 10) / 2;
return bonuses;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public int getBonuses() {
return bonuses;
}
public void setBonuses(int bonuses) {
this.bonuses = bonuses;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
}
Comments
Leave a comment