Procházet zdrojové kódy

Abstract Bank Account

Navya Sanal před 8 roky
rodič
revize
3c38d93625

+ 1
- 0
.idea/modules.xml Zobrazit soubor

@@ -3,6 +3,7 @@
3 3
   <component name="ProjectModuleManager">
4 4
     <modules>
5 5
       <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
6
+      <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
6 7
     </modules>
7 8
   </component>
8 9
 </project>

+ 553
- 379
.idea/workspace.xml
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 89
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/ATM.java Zobrazit soubor

@@ -0,0 +1,89 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+import java.util.HashMap;
4
+
5
+import java.util.Scanner;
6
+public class ATM {
7
+
8
+    //Declaring variables.Here only HashMap.
9
+
10
+    //Account is the base class - it hold the objects of all the derived class.
11
+    //acc - name of HashMap
12
+    Scanner sc  = new Scanner(System.in);
13
+
14
+    HashMap<Integer,Account>acc;
15
+
16
+    //CONSTRUCTOR
17
+    //Initializing variables
18
+    //Inserting values into acc.
19
+    //creating objects for all the derived classes
20
+
21
+
22
+    public ATM()
23
+    {
24
+        SavingsAccount sb = new SavingsAccount(1000,5,8.5);
25
+        CheckingAccount cs = new CheckingAccount(4000);
26
+        BusinessAccount bs = new BusinessAccount(5000);
27
+
28
+        acc =  new HashMap<Integer,Account>();//Initializing HashMap
29
+        acc.put(0001,sb); //adding entries into HashMap
30
+        acc.put(002,cs);
31
+        acc.put(003,bs);
32
+
33
+
34
+    }
35
+     //Methods
36
+
37
+    public void startOpn()
38
+    {
39
+        while(true)
40
+        {
41
+            System.out.println("Enter the card number");
42
+            int cardNum = sc.nextInt();
43
+            Account newAccount =  acc.get(cardNum);//we give the card number so as to get the object(obj of various classes) at that card number.
44
+            System.out.println("Enter the operation to be performed");
45
+            String op = sc.next();
46
+
47
+
48
+
49
+            if(op.equals("withdrawal"))
50
+            {
51
+                System.out.println("Enter the amount");
52
+                int cash = sc.nextInt();
53
+
54
+                boolean x = newAccount.withdrawal(cash);//Pass the value when calling .Cash is obtained from the user using Sys.out.
55
+                if(x == true)
56
+                {
57
+                    System.out.println("Money can be withdrawn");
58
+                }
59
+                else {
60
+                    System.out.println("Amount cannot be withdrawn");
61
+                }
62
+
63
+            }
64
+            if(op.equals("deposit"))
65
+            {
66
+                System.out.println("Enter the amount");
67
+                int cash = sc.nextInt();
68
+                boolean y = newAccount.Deposit(cash);
69
+                if(y == true)
70
+                {
71
+                    System.out.println("Money can be deposited");
72
+                }
73
+                else {
74
+                    System.out.println("Amount cannot be deposited");
75
+                }
76
+
77
+
78
+            }
79
+            if(op.equals("balance"))
80
+            {
81
+                double y = newAccount.getbalanceCheck();
82
+                System.out.println("The balance is" + y);
83
+            }
84
+
85
+        }
86
+    }
87
+
88
+
89
+}

+ 17
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/Account.java Zobrazit soubor

@@ -0,0 +1,17 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public abstract class Account {
4
+
5
+
6
+
7
+
8
+   public abstract boolean withdrawal(double amount);
9
+
10
+   public abstract double getInterest(double amount);
11
+
12
+   public abstract double getbalanceCheck();
13
+
14
+   public abstract boolean Deposit(double amount);
15
+
16
+
17
+}

+ 0
- 7
src/main/java/com/zipcodewilmington/bankaccountlab/BankAccount.java Zobrazit soubor

@@ -1,7 +0,0 @@
1
-package com.zipcodewilmington.bankaccountlab;
2
-
3
-/**
4
- * Created by leon on 1/10/18.
5
- */
6
-public class BankAccount {
7
-}

+ 36
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/BusinessAccount.java Zobrazit soubor

@@ -0,0 +1,36 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class BusinessAccount extends Account {
4
+
5
+    private double balance;
6
+
7
+
8
+//constructor for business class
9
+    public BusinessAccount(int balance) {
10
+        this.balance = balance;
11
+    }
12
+    //methods for business class
13
+
14
+    public boolean withdrawal(double amount)
15
+    {
16
+        return false;
17
+    }
18
+
19
+
20
+    public double getbalanceCheck()
21
+    {
22
+        return this.balance;
23
+    }
24
+
25
+    public boolean Deposit(double amount)
26
+    {
27
+        balance = balance + amount;
28
+        return true;
29
+    }
30
+
31
+
32
+    public double getInterest(double amount)
33
+    {
34
+        return 0;
35
+    }
36
+}

+ 46
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/CheckingAccount.java Zobrazit soubor

@@ -0,0 +1,46 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class CheckingAccount extends Account {
4
+
5
+    private double balance ;
6
+
7
+//constructor
8
+    public  CheckingAccount (double balance)
9
+    {
10
+        this.balance = balance;
11
+
12
+    }
13
+
14
+//methods
15
+    public double getInterest(double amount)
16
+    {
17
+        return 0;
18
+    }
19
+
20
+
21
+
22
+
23
+    public boolean withdrawal(double amount)
24
+    {
25
+        if(balance  > amount)
26
+        {
27
+            balance = balance - amount;
28
+            return true;
29
+        }
30
+        return false;
31
+    }
32
+
33
+    public double getbalanceCheck()
34
+    {
35
+        return this.balance;
36
+    }
37
+
38
+
39
+    public boolean Deposit(double amount)
40
+    {
41
+
42
+            balance  = balance + amount;
43
+            return true;
44
+
45
+    }
46
+}

+ 6
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/MainApplication.java Zobrazit soubor

@@ -4,4 +4,10 @@ package com.zipcodewilmington.bankaccountlab;
4 4
  * Created by leon on 1/10/18.
5 5
  */
6 6
 public class MainApplication {
7
+    public static void main(String[] args)
8
+    {
9
+
10
+        ATM atm = new ATM();
11
+        atm.startOpn();
12
+    }
7 13
 }

+ 68
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/SavingsAccount.java Zobrazit soubor

@@ -0,0 +1,68 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+
4
+public class SavingsAccount extends Account {
5
+    private double balance ;
6
+    //private int accNum;
7
+    private int numOfTrans;
8
+    private int maxTrans;
9
+    private double interestRate;
10
+
11
+
12
+    public SavingsAccount(double balance,int maxTrans,double interestRate) {
13
+
14
+        this.balance = balance;
15
+        this.numOfTrans= 0;             //no need to give this in constructor as its value is 0.
16
+        this.maxTrans = maxTrans;
17
+        this.interestRate = 4.5;
18
+
19
+
20
+    }
21
+
22
+    public boolean withdrawal(double amount)
23
+    {
24
+        if(numOfTrans >= maxTrans)
25
+        {
26
+            System.out.println("you have exceeded maximum");
27
+            return false;
28
+        }
29
+        if(balance > amount)
30
+        {
31
+            balance = balance - amount;
32
+            numOfTrans ++;
33
+            return true;
34
+
35
+        }
36
+        else
37
+        {
38
+            return false;
39
+        }
40
+
41
+    }
42
+
43
+
44
+    public boolean Deposit(double amount) {
45
+        if(numOfTrans > maxTrans)
46
+        {
47
+            System.out.println("You have exceeded");
48
+            return false;
49
+        }
50
+        else
51
+        {
52
+            balance  = balance + amount;
53
+            return true;
54
+        }
55
+
56
+    }
57
+    public double getInterest(double amount)
58
+    {
59
+        balance = amount * 4.5;
60
+        return balance;
61
+    }
62
+    public double getbalanceCheck()
63
+    {
64
+        return balance;
65
+    }
66
+
67
+
68
+}

+ 4
- 0
src/main/java/com/zipcodewilmington/bankaccountlab/main.java Zobrazit soubor

@@ -0,0 +1,4 @@
1
+package com.zipcodewilmington.bankaccountlab;
2
+
3
+public class main {
4
+}

+ 0
- 7
src/test/java/com/zipcodewilmington/bankaccountlab/BankAccountTest.java Zobrazit soubor

@@ -1,7 +0,0 @@
1
-package com.zipcodewilmington.bankaccountlab;
2
-
3
-/**
4
- * Created by leon on 1/10/18.
5
- */
6
-public class BankAccountTest {
7
-}