Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
6 views
Bank Accout Java
Uploaded by
Andrie De las Alas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download now
Download
Save Bank Accout Java For Later
Download
Save
Save Bank Accout Java For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
6 views
Bank Accout Java
Uploaded by
Andrie De las Alas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download now
Download
Save Bank Accout Java For Later
Carousel Previous
Carousel Next
Save
Save Bank Accout Java For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 3
Search
Fullscreen
BankAccount.
java
// Define the BankAccount class
public class BankAccount {
// Attribute for account number
private String accountNumber;
// Attribute for account holder's name
private String accountHolderName;
// Attribute for account balance
private double balance;
// Constructor to initialize BankAccount object
public BankAccount(String accountNumber, String accountHolderName, double
initialBalance) {
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.balance = initialBalance;
}
// Method to deposit money into the account
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposited: " + amount + ". New balance: " +
balance);
} else {
System.out.println("Deposit amount must be positive.");
}
}
// Method to withdraw money from the account
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.println("Withdrew: " + amount + ". New balance: " +
balance);
} else {
System.out.println("Insufficient balance or invalid amount.");
}
}
// Method to check the account balance
public double checkBalance() {
return balance;
}
// Getter method for account number
public String getAccountNumber() {
return accountNumber;
}
// Getter method for account holder's name
public String getAccountHolderName() {
return accountHolderName;
}
}
// Define the SavingsAccount subclass that extends BankAccount
class SavingsAccount extends BankAccount {
// Attribute for interest rate
private double interestRate;
// Constructor to initialize SavingsAccount object
public SavingsAccount(String accountNumber, String accountHolderName, double
initialBalance, double interestRate) {
super(accountNumber, accountHolderName, initialBalance); // Call the
constructor of the superclass
this.interestRate = interestRate;
}
// Method to apply interest to the balance
public void applyInterest() {
double interest = checkBalance() * interestRate / 100; // Calculate
interest
deposit(interest); // Add interest to the balance
System.out.println("Interest applied: " + interest + ". New balance: " +
checkBalance());
}
// Getter method for interest rate
public double getInterestRate() {
return interestRate;
}
// Setter method for interest rate
public void setInterestRate(double interestRate) {
if (interestRate > 0) {
this.interestRate = interestRate;
} else {
System.out.println("Interest rate must be positive.");
}
}
}
// Main class to test the BankAccount and SavingsAccount classes
public class Main {
public static void main(String[] args) {
// Create a BankAccount object
BankAccount account = new BankAccount("123456789", "Henri Lionel", 1000.0);
System.out.println("Current balance: " + account.checkBalance()); //
Check balance
account.deposit(4000.0); // Deposit money
account.withdraw(3000.0); // Withdraw money
System.out.println("Current balance: " + account.checkBalance()); // Check
balance
// Create a SavingsAccount object
SavingsAccount savings = new SavingsAccount("888888888", "Amphitrite Jun",
2000.0, 5.0);
savings.applyInterest(); // Apply interest
System.out.println("Savings account balance: " +
savings.checkBalance()); // Check balance
}
}
You might also like
Modern Robotics Solutions
PDF
50% (2)
Modern Robotics Solutions
156 pages
AS Project - 3 Business Report
PDF
0% (1)
AS Project - 3 Business Report
10 pages
Run Savings Account
PDF
100% (1)
Run Savings Account
2 pages
Pokémon The Series: RGBY: Chapter 1: Pokemon, I Choose You!!!
PDF
No ratings yet
Pokémon The Series: RGBY: Chapter 1: Pokemon, I Choose You!!!
21 pages
j Worksheet6 Inheritace
PDF
No ratings yet
j Worksheet6 Inheritace
6 pages
Bank_Management_Complete
PDF
No ratings yet
Bank_Management_Complete
7 pages
java 8 - 1
PDF
No ratings yet
java 8 - 1
2 pages
r195375w Guzha Panashe H
PDF
No ratings yet
r195375w Guzha Panashe H
6 pages
Banking System N
PDF
No ratings yet
Banking System N
5 pages
op
PDF
No ratings yet
op
6 pages
Banks
PDF
No ratings yet
Banks
5 pages
Codigo Do Robinho
PDF
No ratings yet
Codigo Do Robinho
4 pages
A Bank Account Class
PDF
No ratings yet
A Bank Account Class
10 pages
Coding Example
PDF
No ratings yet
Coding Example
3 pages
Banking Application
PDF
No ratings yet
Banking Application
3 pages
Oop First LAboratory
PDF
No ratings yet
Oop First LAboratory
2 pages
Screenshot 2024-09-09 at 1.21.22 PM
PDF
No ratings yet
Screenshot 2024-09-09 at 1.21.22 PM
2 pages
03HandsOnAct1 Code
PDF
No ratings yet
03HandsOnAct1 Code
2 pages
Oop First LAboratory
PDF
No ratings yet
Oop First LAboratory
2 pages
PSOOPL_experiment 9-2
PDF
No ratings yet
PSOOPL_experiment 9-2
8 pages
Java Lab File
PDF
No ratings yet
Java Lab File
22 pages
Bank Account
PDF
No ratings yet
Bank Account
3 pages
import java
PDF
No ratings yet
import java
11 pages
Java Programming Lab File - 049
PDF
No ratings yet
Java Programming Lab File - 049
19 pages
Run Savings Account
PDF
No ratings yet
Run Savings Account
2 pages
Run
PDF
No ratings yet
Run
2 pages
LAB EXAM
PDF
No ratings yet
LAB EXAM
7 pages
BankingSystem_java
PDF
No ratings yet
BankingSystem_java
7 pages
Practical 9
PDF
No ratings yet
Practical 9
9 pages
02 Task Performance 1
PDF
No ratings yet
02 Task Performance 1
2 pages
import java - Copy
PDF
No ratings yet
import java - Copy
5 pages
Simple Banking Application Using CORE
PDF
No ratings yet
Simple Banking Application Using CORE
7 pages
Second
PDF
No ratings yet
Second
3 pages
Project
PDF
No ratings yet
Project
8 pages
Java Lab
PDF
No ratings yet
Java Lab
44 pages
Saving Accounts
PDF
No ratings yet
Saving Accounts
4 pages
slip 15
PDF
No ratings yet
slip 15
4 pages
Bank Exception.java
PDF
No ratings yet
Bank Exception.java
5 pages
Banking System
PDF
No ratings yet
Banking System
10 pages
OOB
PDF
No ratings yet
OOB
5 pages
Outputs_20250418_064200_0000
PDF
No ratings yet
Outputs_20250418_064200_0000
10 pages
Anudip Bankportal
PDF
No ratings yet
Anudip Bankportal
3 pages
Lab Copy 3
PDF
No ratings yet
Lab Copy 3
20 pages
SodaPDF Converted Project - 10
PDF
No ratings yet
SodaPDF Converted Project - 10
23 pages
Static Method Qs
PDF
No ratings yet
Static Method Qs
3 pages
omoops.6
PDF
No ratings yet
omoops.6
4 pages
Anilkumar Java OopsAssignment
PDF
No ratings yet
Anilkumar Java OopsAssignment
13 pages
A Beautiful Journey Through Olympiad Geometry (1.0.0)
PDF
100% (1)
A Beautiful Journey Through Olympiad Geometry (1.0.0)
8 pages
java saving account exercise
PDF
No ratings yet
java saving account exercise
1 page
Set 7
PDF
No ratings yet
Set 7
9 pages
лаба 5
PDF
No ratings yet
лаба 5
41 pages
Java Interfaces: Attribute Datatype
PDF
100% (1)
Java Interfaces: Attribute Datatype
33 pages
CAYAATMCODE
PDF
No ratings yet
CAYAATMCODE
8 pages
Java 4
PDF
No ratings yet
Java 4
6 pages
Project 2... 0
PDF
No ratings yet
Project 2... 0
4 pages
Lab 4 - Virtual Lab - 20MIS1115
PDF
No ratings yet
Lab 4 - Virtual Lab - 20MIS1115
12 pages
2.1 Pratice
PDF
No ratings yet
2.1 Pratice
5 pages
Chanbgee
PDF
No ratings yet
Chanbgee
2 pages
Vrushali Jani JAVA Practice (11.10.21)
PDF
No ratings yet
Vrushali Jani JAVA Practice (11.10.21)
10 pages
Astitwo Java Code
PDF
No ratings yet
Astitwo Java Code
7 pages
Exp 1.3
PDF
No ratings yet
Exp 1.3
7 pages
Inheritance, Overloading and Overriding: Recall
PDF
No ratings yet
Inheritance, Overloading and Overriding: Recall
21 pages
Stripe Integration in Angular: A Step-by-Step Guide to Creating Payment Functionality
From Everand
Stripe Integration in Angular: A Step-by-Step Guide to Creating Payment Functionality
Abdelfattah Ragab
No ratings yet
Library System
PDF
No ratings yet
Library System
4 pages
Untitled
PDF
No ratings yet
Untitled
2 pages
A Sun in A Cloudy Day
PDF
No ratings yet
A Sun in A Cloudy Day
1 page
Eim10 w3 4
PDF
No ratings yet
Eim10 w3 4
2 pages
Ash's Pokémon-WPS Office
PDF
No ratings yet
Ash's Pokémon-WPS Office
2 pages
Solving and Modeling Ken-Ken Puzzle by Using Hybrid Genetics Algorithm
PDF
No ratings yet
Solving and Modeling Ken-Ken Puzzle by Using Hybrid Genetics Algorithm
5 pages
Data Sheet: Subc Nickel-Zinc Batteries
PDF
No ratings yet
Data Sheet: Subc Nickel-Zinc Batteries
2 pages
Scribd Paid Access End User License Agreement
PDF
No ratings yet
Scribd Paid Access End User License Agreement
7 pages
The Inn at Five Points
PDF
100% (9)
The Inn at Five Points
16 pages
Mathematics
PDF
No ratings yet
Mathematics
16 pages
The Main Variants of The English Language
PDF
No ratings yet
The Main Variants of The English Language
15 pages
Business Studies Paper 2 Revision Amended
PDF
No ratings yet
Business Studies Paper 2 Revision Amended
6 pages
RMC Jose Mourinho Session 2
PDF
100% (1)
RMC Jose Mourinho Session 2
1 page
013 ORAL Wanderlust
PDF
No ratings yet
013 ORAL Wanderlust
1 page
Loctite 243: Technical Data Sheet
PDF
No ratings yet
Loctite 243: Technical Data Sheet
6 pages
AJA-Software-Installer MacOS v16.0.3 ReleaseNotes
PDF
No ratings yet
AJA-Software-Installer MacOS v16.0.3 ReleaseNotes
35 pages
International Finance Manual PDF
PDF
100% (3)
International Finance Manual PDF
213 pages
Separate System Upgrade and Data Migration Guide
PDF
No ratings yet
Separate System Upgrade and Data Migration Guide
68 pages
3.0-TDI Clean Diesel Engine PDF
PDF
No ratings yet
3.0-TDI Clean Diesel Engine PDF
111 pages
The FMEDA Tool For Cyclone V Series For IEC 61508
PDF
No ratings yet
The FMEDA Tool For Cyclone V Series For IEC 61508
21 pages
ArevaTD PowerTransformersReactors PTR Overview Eng
PDF
No ratings yet
ArevaTD PowerTransformersReactors PTR Overview Eng
12 pages
preivet crunchyroll
PDF
No ratings yet
preivet crunchyroll
14 pages
Nguyen Quang Huy - Application Letter & CV
PDF
No ratings yet
Nguyen Quang Huy - Application Letter & CV
4 pages
Apparel Merchandising, Costing and Export Documentation
PDF
No ratings yet
Apparel Merchandising, Costing and Export Documentation
2 pages
Wifi Direct
PDF
No ratings yet
Wifi Direct
71 pages
LDCS
PDF
No ratings yet
LDCS
12 pages
Ross, Whit Taker, Little - Design of Submarine Pressure Hulls To Withstand Buckling Under External Hydro Static Pressure
PDF
No ratings yet
Ross, Whit Taker, Little - Design of Submarine Pressure Hulls To Withstand Buckling Under External Hydro Static Pressure
6 pages
Color Scheme
PDF
No ratings yet
Color Scheme
8 pages
Sun2000 33KTL
PDF
No ratings yet
Sun2000 33KTL
2 pages
Dragon Quest VI Realms of Revelation Walkthrough
PDF
No ratings yet
Dragon Quest VI Realms of Revelation Walkthrough
367 pages
BPO: Barclays: Cvent: British Airways: Genpact: Salary Till 7 Lacs
PDF
No ratings yet
BPO: Barclays: Cvent: British Airways: Genpact: Salary Till 7 Lacs
3 pages
COLOUR MIXING GUIDE Satin - Ice
PDF
No ratings yet
COLOUR MIXING GUIDE Satin - Ice
2 pages
CS Project Store Management Updated
PDF
No ratings yet
CS Project Store Management Updated
24 pages
Documents
Computers
Programming