-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntermediate Module 2.java
More file actions
86 lines (62 loc) · 2.83 KB
/
Intermediate Module 2.java
File metadata and controls
86 lines (62 loc) · 2.83 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
Ques 2:
import java.util.Scanner;
class BankAccount {
String accountHolderName;
int accountNumber;
double balance;
// Constructor
public BankAccount(String accountHolderName, int accountNumber, double initialDeposit) {
this.accountHolderName = accountHolderName;
this.accountNumber = accountNumber;
this.balance = initialDeposit;
}
// Method to display account details
public void displayAccountDetails() {
System.out.println(String.format("Balance: ₹%.2f", balance));
}
}
class SavingsAccount extends BankAccount {
// Constructor
public SavingsAccount(String accountHolderName, int accountNumber, double initialDeposit) {
super(accountHolderName, accountNumber, initialDeposit);
}
// Additional methods specific to SavingsAccount can be added here
}
class CurrentAccount extends BankAccount {
double overdraftLimit;
// Constructor
public CurrentAccount(String accountHolderName, int accountNumber, double initialDeposit, double overdraftLimit) {
super(accountHolderName, accountNumber, initialDeposit);
this.overdraftLimit = overdraftLimit;
}
// Method to display account details including overdraft limit
@Override
public void displayAccountDetails() {
super.displayAccountDetails();
System.out.println(String.format("Overdraft Limit: ₹%.2f", overdraftLimit));
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String accountType = scanner.nextLine();
String accountHolderName = scanner.nextLine();
int accountNumber = scanner.nextInt();
double initialDeposit = scanner.nextDouble();
if (accountType.equalsIgnoreCase("SavingsAccount")) {
SavingsAccount savingsAccount = new SavingsAccount(accountHolderName, accountNumber, initialDeposit);
System.out.println("Account Created: SavingsAccount for " + savingsAccount.accountHolderName +
" with Account Number " + savingsAccount.accountNumber);
savingsAccount.displayAccountDetails();
} else if (accountType.equalsIgnoreCase("CurrentAccount")) {
double overdraftLimit = scanner.nextDouble();
CurrentAccount currentAccount = new CurrentAccount(accountHolderName, accountNumber, initialDeposit, overdraftLimit);
System.out.println("Account Created: CurrentAccount for " + currentAccount.accountHolderName +
" with Account Number " + currentAccount.accountNumber);
currentAccount.displayAccountDetails();
} else {
System.out.println("Invalid Account Type. Please enter either SavingsAccount or CurrentAccount.");
}
scanner.close();
}
}