MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / Account

Class Account

Programs/bankSystem.java:15–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14// class created for storing attributes and methods of account -
15class Account {
16 Scanner sc = new Scanner(System.in);
17 public String name; // for storing name of account holder
18 public String date; // for storing the date on which the account was created
19 public String nationality; // for storing nationality of account holder
20 public String verifNum; // for storing verification number such as PAN, Aadhar, etc.
21 public static int AccNumCnt = 0; // account number counter
22 public int AccID = 1000; // for storing account id
23 public double balance; // for storing balance
24
25 // function to create an account -
26 public void createAccount() {
27 System.out.println("Enter your name: ");
28 name = sc.nextLine(); // get name
29 System.out.println("Enter date: ");
30 date = sc.nextLine(); // get date
31 System.out.println("Enter nationality: ");
32 nationality = sc.nextLine(); // get nationality
33 System.out.println("Enter Aadhar/PAN/verification number: ");
34 verifNum = sc.nextLine(); // get verification number
35 do {
36 System.out.println("Basic balance: ");
37 balance = sc.nextDouble(); // initial deposit (must be minimum Rs.1000)
38 if (balance < 1000) {
39 System.out.println("Initial balance should be minimum Rs.1000!");
40 }
41 else {
42 System.out.println("Account created!");
43 }
44 } while (balance < 1000);
45 AccNumCnt++;
46 AccID = AccNumCnt; // assigns account id automatically
47 }
48
49 // function to deposit money in existing account -
50 public void depositMoney() {
51 double depAmt = 0;
52 System.out.println("Enter amount that you want to deposit: ");
53 depAmt = sc.nextDouble();
54 balance = balance + depAmt;
55 System.out.println("Your new balance is: " + balance);
56 }
57
58 // function to withdraw money from an existing account -
59 public void withdrawMoney() {
60 double witAmt = 0;
61 do {
62 System.out.println("Enter amount that you want to withdraw: ");
63 witAmt = sc.nextDouble();
64 // check if withdrawal amount is less than balance, only proceed if true -
65 if (witAmt > balance) {
66 System.out.println("Account balance is less! Cannot withdraw...transaction failed!");
67 }
68 } while (witAmt > balance);
69 balance = balance - witAmt;
70 System.out.println("Your current balance is: " + balance);
71 }
72

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected