-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
107 lines (100 loc) · 3.68 KB
/
BankAccount.java
File metadata and controls
107 lines (100 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package BankAccount;
import java.util.Scanner;
import java.util.Date;
public class BankAccount
{
int AccNo;
String AcHolderName;
String AccType;
float AccBalance;
Date AccCreatedOn;
static Scanner sc = new Scanner(System.in);
public void openAccount(int accNo, String acHolderName, String accType, float accBalance, Date accCreatedOn)
{
AccNo = accNo;
AcHolderName = acHolderName;
AccType = accType;
AccBalance = accBalance;
AccCreatedOn = accCreatedOn;
}
public void displyAccountDetails()
{
System.out.println("Account Number: " + AccNo);
System.out.println("Account Holder Name: " + AcHolderName);
System.out.println("Account Type: " + AccType);
System.out.println("Account Balance: " + AccBalance);
System.out.println("Account Created On: " + AccCreatedOn);
}
public void deposit()
{
System.out.println("Enter the amount you want to deposit:");
float amount = sc.nextFloat();
sc.nextLine();
AccBalance += amount;
System.out.println("Deposited: " + amount);
}
public void withdraw()
{
System.out.println("Enter the amount you want to withdrar from the account:");
float amount = sc.nextFloat();
sc.nextLine();
AccBalance -= amount;
System.out.println("Withdrawn: " + amount);
}
}
abstract class Main
{
public static void main (String [] args)
{ int choice;
int AccNo;
String AcHolderName;
String AccType;
float AccBalance;
Date AccCreatedOn;
Scanner sc = new Scanner(System.in);
BankAccount ba = new BankAccount();
do {
System.out.println("Please Enter the Operation You Want to Perform:\n" +
"If you want to Deposit then please Enter 1 \n" +
"If you want to Withdraw then please Enter 2 \n"
+ " If you want to Create Account Details then please Enter 3 \n"
+ "If you want to Display Account then please Enter 4 \n "
+" If you want to Exit then please Enter 5 \n ");
choice = sc.nextInt();
sc.nextLine();
switch (choice)
{
case 1:
ba.deposit();
break;
case 2:
ba.withdraw();
break;
case 3:
System.out.println("Please Enter the Name : ");
AcHolderName = sc.nextLine();
System.out.println("Please Enter the Account Number You want to give to your account : ");
AccNo = sc.nextInt();
sc.nextLine();
System.out.println("Enter Your Account Type:");
AccType = sc.nextLine();
System.out.println("Enter the Initial Amount you want to deposit to your account:");
AccBalance = sc.nextFloat();
sc.nextLine();
AccCreatedOn = new Date();
System.out.println("Account Created Successfully!");
ba.openAccount(AccNo, AcHolderName, AccType, AccBalance, AccCreatedOn);;
break;
case 4:
ba.displyAccountDetails();
break;
case 5:
System.out.println("Thank You for Using Our Services!");
break;
default:
System.out.println("Invalid Choice! Please Try Again.");
}
} while (choice != 5);
sc.close();
}
}