Write a Java Program to create a Bank Account
Write a Java Program to create Class Account.
Java Oops
Write a Java Program to create a Class Account
Solution :-
class Account
{
int acno;
String name;
double bal;
void insert(int a , String n , double b)
{
acno = a;
name = n;
bal = b;
}
void deposit(double b)
{
bal = bal + b;
System.out.println(“The new balanace is :- “+b);
}
void withdrawal(double b)
{
bal = bal – b;
System.out.println(“The Withdrawal balanace is :- “+b);
}
void checkbal()
{
System.out.println(acno + ” “+ name + ” “+ bal);
}
}
class Main
{
public static void main(String args[])
{
Account a1 = new Account();
a1.insert(123654,”Abc”,45000.50);
a1.checkbal();
a1.withdrawal(25000);
a1.checkbal();
a1.deposit(45000);
a1.checkbal();
}
}
Dynamic :-
import java.util.*;
class Account
{
int acno;
String name;
double bal;
void insert(int a , String n , double b)
{
acno = a;
name = n;
bal = b;
}
void deposit(double b)
{
bal = bal + b;
System.out.println(“The new balanace is :- “+b);
}
void withdrawal(double b)
{
bal = bal – b;
System.out.println(“The Withdrawal balanace is :- “+b);
}
void checkbal()
{
System.out.println(acno + ” “+ name + ” “+ bal);
}
}
class Main
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int acno,amt;
String name;
System.out.println(“Enter Your Account number :- “);
acno = in.nextInt();
System.out.println(“Enter Your Name :- “);
name = in.next();
System.out.println(“Enter Your Balance :- “);
amt = in.nextInt();
Account a1 = new Account();
a1.insert(acno,name,amt);
a1.checkbal();
a1.deposit(40000);
a1.checkbal();
a1.withdrawal(60000);
a1.checkbal();
}
}
Output :-
TRY THIS CODE
Popular Videos
UX for Teams
Learn the basics and a bit beyond to improve your backend dev skills.
Designer
SEO & Instagram
Learn the basics and a bit beyond to improve your backend dev skills.
Designer