Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views2 pages

Bankaccount 2

The document defines a Java class 'Account' with attributes for account holder's name, account number, and balance, along with multiple constructors for creating account instances. It includes methods for depositing and withdrawing money, as well as displaying account details. The 'BnkAcc' class demonstrates creating account objects and performing operations on them.

Uploaded by

feqojoge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Bankaccount 2

The document defines a Java class 'Account' with attributes for account holder's name, account number, and balance, along with multiple constructors for creating account instances. It includes methods for depositing and withdrawing money, as well as displaying account details. The 'BnkAcc' class demonstrates creating account objects and performing operations on them.

Uploaded by

feqojoge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

class Account{

// variables
String name;
int accNum;
double balance;

// constructors
Account(){
this.name = "Unknown";
this.accNum = 00000;
this.balance = 0.00;
}
Account(String name){
this.name = name;
this.accNum = 784512;
this.balance = 0.00;
}
Account(String name, int accNum){
this.name = name;
this.accNum = accNum;
this.balance = 0.00;
}
Account(String name, int accNum, double balance){
this.name = name;
this.accNum = accNum;
this.balance = balance;
}

// methods to tamper balance


double deposit(double money){
return balance += money;
}
double withdraw(double money){
return balance -= money;
}

// displaying the Account details


void accDetails(){
System.out.print("\n\t ACCOUNT DETAILS");
System.out.println("\n--------------------------------");
System.out.println("Holder Name: " + name);
System.out.println("Account Number: " + accNum);
System.out.println("Balance: $" + balance);
System.out.println("--------------------------------");
}
}

public class BnkAcc{


public static void main(String[] args){

// making the Bankaccount object


Account acc1 = new Account("John", 4654650, 456.00);
acc1.accDetails();
acc1.deposit(100.54);
acc1.accDetails();
Account acc2 = new Account("Henry", 598750);
acc2.accDetails();

}
}

You might also like