0% found this document useful (0 votes)
5 views14 pages

Oop With Java Programming Deepika

The document outlines a Java program for managing bank accounts using Object-Oriented Programming principles. It defines an 'Account' class with methods for creating accounts, depositing, withdrawing, and printing account details. The 'Bank' class contains the main method to interact with the user and execute account operations based on user choices.
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)
5 views14 pages

Oop With Java Programming Deepika

The document outlines a Java program for managing bank accounts using Object-Oriented Programming principles. It defines an 'Account' class with methods for creating accounts, depositing, withdrawing, and printing account details. The 'Bank' class contains the main method to interact with the user and execute account operations based on user choices.
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/ 14

OOP WITH JAVA PROGRAMMING

NAME : DEEPIKA SHARMA


USN : 1NX24CS030

1. Create a class :
Account data members:
Accno : integer
name :String
Phone No: integer
balance_amt:float

methods :
a. CreateAccount() method to create
an account.
b. Deposit() method to deposit amount
to an account.
c. Withdraw() method which gets
the amount to be withdrawn from
his/her account.
d. PrintAccount() method to
display account details.

Account.java
import
java.util.Scanner;

public class Account {


//instance
variables int
accno; String
name; int
phone_no; float
balance_amt;
//methods
public void createAccount(){
Scanner scanner = new
Scanner(System.in);

System.out.println("Welcome to State of
JNQ !!");
System.out.println("Enter the
following details : ");
System.out.println("Account
number :
");
accno=scanner.nextInt();
System.out.println("Account holder
name : ");
name=scanner.next();
System.out.println("Phone number :
");
phone_no=scanner.nextInt(
);
System.out.println("openin
g balance :
");
balance_amt=scanner.nextFloat();

public void deposit(float amt){


balance_amt=balance_amt+amt;
printAccount();
}

public void withDraw(float amt){


if(amt>balance_amt){
System.out.println("Insufficient
balance ");
}
else
{
balance_amt=balance_amt-amt;
printAccount();
}
}

public void printAccount(){


System.out.println("ACCOUNT
SUMMARY*");
System.out.println("Account
number : "+accno);
System.out.println("Account holder
name : "+name);
System.out.println("Phone number :
"+phone_no);
System.out.println("opening balance
: "+balance_amt);
System.out.println("**************
***");
}
}

Bank.java import
java.util.Scanner;

public class Bank


{
public static void main(String[] args){
Scanner scanner = new
Scanner(System.in);
Account a = new
Account(); a.createAccount();
int choice = 0;
float amt =0;
while(choice!=4){
System.out.println("Enter your
choice : ");
System.out.println("1.Deposit
2.Withdraw 3.Display 4.Exit");
choice=scanner.nextInt();
switch ( choice) { case 1:
System.out.println("Enter the
amount : ");
amt=scanner.nextFloat();
a.deposit(amt);
break
;

case 2:
System.out.println("Enter the
amount : ");
amt=scanner.nextFloat();
a.withDraw(amt);
break;
case 3:
a.printAccount();
break; case 4:
System.out.println("Exiting
");
break; default:
System.out.println("Invalid
choice. Try again");

}
}
}

}
Output:

You might also like