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
Run Savings Account
PDF
100% (1)
Run Savings Account
2 pages
DCOM 150-Lab 1 - Hexa-Decimal Numbering System and File Signature - Fall 2016
PDF
0% (1)
DCOM 150-Lab 1 - Hexa-Decimal Numbering System and File Signature - Fall 2016
6 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
Untitled
PDF
No ratings yet
Untitled
2 pages
Library System
PDF
No ratings yet
Library System
4 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
(November-2019) Braindump2go New PCNSE VCE Dumps Free Share
PDF
No ratings yet
(November-2019) Braindump2go New PCNSE VCE Dumps Free Share
6 pages
CICfscupdate PDF
PDF
No ratings yet
CICfscupdate PDF
1 page
Automator User Guide
PDF
No ratings yet
Automator User Guide
22 pages
Tree Menu Magic 2
PDF
No ratings yet
Tree Menu Magic 2
77 pages
Syllabus: Certificate Course in Information Technology (Cit) Duration:-6 Months
PDF
No ratings yet
Syllabus: Certificate Course in Information Technology (Cit) Duration:-6 Months
2 pages
Protocol Description Ipx / SPX (Nwlink)
PDF
No ratings yet
Protocol Description Ipx / SPX (Nwlink)
2 pages
Assignment 1
PDF
No ratings yet
Assignment 1
5 pages
Clocktimizer Installation Guide 2023
PDF
No ratings yet
Clocktimizer Installation Guide 2023
48 pages
Fortinet and Siemens Security Solutions
PDF
No ratings yet
Fortinet and Siemens Security Solutions
2 pages
Project Choosing Majors: Name: Dang Nhat Huy Student ID: ITITIU20043
PDF
No ratings yet
Project Choosing Majors: Name: Dang Nhat Huy Student ID: ITITIU20043
3 pages
Chapter 1
PDF
No ratings yet
Chapter 1
16 pages
Linux - Fundamentals Complete
PDF
No ratings yet
Linux - Fundamentals Complete
349 pages
PART-I: Multiple Choices: Jimma University
PDF
100% (1)
PART-I: Multiple Choices: Jimma University
6 pages
Preparing For PCA Workbook
PDF
No ratings yet
Preparing For PCA Workbook
87 pages
Security Best Practices in AOS v1.7 PDF
PDF
No ratings yet
Security Best Practices in AOS v1.7 PDF
70 pages
Donasi Cianjur
PDF
No ratings yet
Donasi Cianjur
10 pages
GT
PDF
100% (2)
GT
122 pages
Install Inst, Premier Safe Shutdown: Artwork Consists of Two (2) 8 Inch X 11 Inch Pages
PDF
No ratings yet
Install Inst, Premier Safe Shutdown: Artwork Consists of Two (2) 8 Inch X 11 Inch Pages
3 pages
Logcat
PDF
No ratings yet
Logcat
151 pages
TESA REFLEX Panel Product Presentation V1 EN
PDF
No ratings yet
TESA REFLEX Panel Product Presentation V1 EN
24 pages
IGS-NT Installation Guide 05-2013r1
PDF
No ratings yet
IGS-NT Installation Guide 05-2013r1
128 pages
Linux Programming
PDF
No ratings yet
Linux Programming
150 pages
Exception Handling in Python
PDF
No ratings yet
Exception Handling in Python
18 pages
Sophos Mobile Configure Apple DEP - Business Manager
PDF
No ratings yet
Sophos Mobile Configure Apple DEP - Business Manager
38 pages
DC Power Electronics: Electricity and New Energy
PDF
No ratings yet
DC Power Electronics: Electricity and New Energy
39 pages
Plant Disease Detection
PDF
No ratings yet
Plant Disease Detection
13 pages
9 Different Data Types To Better Understand Your Business
PDF
No ratings yet
9 Different Data Types To Better Understand Your Business
7 pages
PF Source Code
PDF
No ratings yet
PF Source Code
9 pages
PROGCFZ User Manual
PDF
No ratings yet
PROGCFZ User Manual
40 pages
Documents
Computers
Programming