Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created bank_account.java #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions JavaHackerrank/bank_account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*Design and write a class to represent a bank account that includes the following members:
a. Data members
· Owner name
· Account number
· Balance amount in the account
b. Methods members
· To assign initial values
· To deposit an amount
· To withdraw an amount after checking balance
· To display the owner name and balance*/

import java.util.Scanner;
public class BankAccount1
{
int acc_no;
String name;
float bal,amt,withdraw;
Scanner A=new Scanner(System.in);
void read()
{
System.out.println("Enter Owner's Name: ");
name=A.next();
System.out.println("Enter Account Number: ");
acc_no=A.nextInt();
}
void deposit()
{
int choice;
float current,saving;
Scanner A=new Scanner(System.in);
System.out.println("Enter Initial Amount: ");
amt=A.nextFloat();
System.out.println("1.Savings Account");
System.out.println("2.Current Account");
System.out.println("Enter Choice: ");
choice=A.nextInt();
switch(choice)
{
case 1:
saving=amt;
System.out.println("Amount In Savings Account Is: "+saving);
break;
case 2:
current=amt;
System.out.println("Amount In Savings Account Is: "+current);
break;
default:
break;

}
}
void withdraw()
{
Scanner A=new Scanner(System.in);
System.out.println("Enter Withdrawal Amount: ");
withdraw=A.nextFloat();
bal=amt-withdraw;
amt=bal;
if(bal>0)
{
System.out.println("Balance Amount Left Is :"+bal);
}
else
{
System.out.println("Zero Balance");
}
}
void display()
{
System.out.println("Owner's Name Is: "+name);
System.out.println("Balance Left In Bank Is: "+bal);
}
public static void main(String[] args) {
BankAccount1 B1=new BankAccount1();
B1.read();
B1.deposit();
B1.withdraw();
B1.display();

}

}