SlideShare a Scribd company logo
2
Most read
Bank account in java
Bank Account in Java
There is a Bank Account class having methods of deposit and withdrawal which is being accessed by the
tester class. Amount deposited or withdrawn is shown through balance remaining.
import java.util.Scanner;
public class BankAccount
{
public double balance;
public String name;
public BankAccount(double theBalance, String theName)
{
balance = theBalance;
name = theName;
}
public void deposit(double amount)
{
balance = balance + amount;
}
public void withdraw(double amount)
{
balance = balance - amount;
}
}
public class Tester
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the initial balance: ");
double balance = in.nextDouble();
in.nextLine();
System.out.print("Enter the account name: ");
String name = in.nextLine();
BankAccount myAccount = new BankAccount(balance, name);
myAccount.deposit(505.22);
System.out.println(myAccount.balance);
myAccount.withdraw(100);
System.out.printf("The %s account balance is, $%.2fn",
myAccount.name, myAccount.balance);
}
}

More Related Content

PPTX
Tab - Subtab Navigation
PPT
Bank management system with java
PPT
Banking system (final)
DOCX
documentation on bank management system
DOC
SYNOPSIS ON BANK MANAGEMENT SYSTEM
PDF
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
PDF
The java class Account that simultes the Account class.pdf
PDF
BankAccount.java A bank account has a balance that can be cha.pdf
Tab - Subtab Navigation
Bank management system with java
Banking system (final)
documentation on bank management system
SYNOPSIS ON BANK MANAGEMENT SYSTEM
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
The java class Account that simultes the Account class.pdf
BankAccount.java A bank account has a balance that can be cha.pdf

Similar to Bank account in java (12)

PDF
You are not setting any values for those variables(name, ID, interes.pdf
TXT
PDF
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
PDF
Hi,I have updated the code as per your requirement. Highlighted th.pdf
PDF
Java programI made this Account.java below. Using the attached cod.pdf
PDF
Create a new Java project and add the Account class into the source co.pdf
DOCX
java experiments and programs
PDF
I need help creating a basic and simple Java program. Here is the ex.pdf
PDF
SavingsAccount.javapublic class SavingsAccount{             .pdf
DOCX
Tmpj3 01 201181102muhammad_tohir
PDF
public class NegativeAmountException extends Exception {    .pdf
PDF
Inheritance
You are not setting any values for those variables(name, ID, interes.pdf
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdf
Java programI made this Account.java below. Using the attached cod.pdf
Create a new Java project and add the Account class into the source co.pdf
java experiments and programs
I need help creating a basic and simple Java program. Here is the ex.pdf
SavingsAccount.javapublic class SavingsAccount{             .pdf
Tmpj3 01 201181102muhammad_tohir
public class NegativeAmountException extends Exception {    .pdf
Inheritance
Ad

More from Programming Homework Help (8)

PDF
Java Assignment Help
PDF
C# Assignmet Help
PDF
C# Assignmet Help
PDF
Family tree in java
PDF
Binary tree in java
PDF
Mouse and Cat Game In C++
PDF
Word games in c
PDF
Card Games in C++
Java Assignment Help
C# Assignmet Help
C# Assignmet Help
Family tree in java
Binary tree in java
Mouse and Cat Game In C++
Word games in c
Card Games in C++
Ad

Recently uploaded (20)

PPTX
Pharma ospi slides which help in ospi learning
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
From loneliness to social connection charting
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Pharma ospi slides which help in ospi learning
O5-L3 Freight Transport Ops (International) V1.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Renaissance Architecture: A Journey from Faith to Humanism
Abdominal Access Techniques with Prof. Dr. R K Mishra
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
Onica Farming 24rsclub profitable farm business
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Structure & Organelles in detailed.
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Open folder Downloads.pdf yes yes ges yes
Module 3: Health Systems Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
From loneliness to social connection charting
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
human mycosis Human fungal infections are called human mycosis..pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...

Bank account in java

  • 2. Bank Account in Java There is a Bank Account class having methods of deposit and withdrawal which is being accessed by the tester class. Amount deposited or withdrawn is shown through balance remaining. import java.util.Scanner; public class BankAccount { public double balance; public String name; public BankAccount(double theBalance, String theName) { balance = theBalance; name = theName; } public void deposit(double amount) { balance = balance + amount; } public void withdraw(double amount)
  • 3. { balance = balance - amount; } } public class Tester { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter the initial balance: "); double balance = in.nextDouble(); in.nextLine(); System.out.print("Enter the account name: "); String name = in.nextLine(); BankAccount myAccount = new BankAccount(balance, name); myAccount.deposit(505.22); System.out.println(myAccount.balance); myAccount.withdraw(100);
  • 4. System.out.printf("The %s account balance is, $%.2fn", myAccount.name, myAccount.balance); } }