8. Develop a program by designing a class to represent a bank account. Include the
following members:
Data Members:
Name of the Depositor
Account Number
Type of account
Balance
Methods:
getdetails( ) ---To assign initial values
deposit( ) ---To deposit an amount
withdraw( ) ---To withdraw an amount after checking balance
display( )--- To display the name and balance.
public class BankAccount {
private String nameOfDepositor;
private int accountNumber;
private String typeOfAccount;
private double balance;
public void getDetails(String nameOfDepositor, int accountNumber, String typeOfAccount, double balance) {
this.nameOfDepositor = nameOfDepositor;
this.accountNumber = accountNumber;
this.typeOfAccount = typeOfAccount;
this.balance = balance;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
if (balance >= amount) {
balance -= amount;
}
}
public void display() {
System.out.println(nameOfDepositor + " Balance: " + balance);
}
}
Comments
Leave a comment