From 475de50f1c7a985b569321fb5e538cc854854e09 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <72411579+kn0wabhi@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:59:34 +0530 Subject: [PATCH] Created bank_account.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- JavaHackerrank/bank_account.java | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 JavaHackerrank/bank_account.java diff --git a/JavaHackerrank/bank_account.java b/JavaHackerrank/bank_account.java new file mode 100644 index 00000000..c12d809e --- /dev/null +++ b/JavaHackerrank/bank_account.java @@ -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(); + + } + +}