Skip to content

Commit 021f578

Browse files
committed
Refactor account creation to include account type in constructor and improve output messages for account creation
1 parent 13cdabe commit 021f578

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/Main.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,25 @@ public static void main(String[] args) {
4646
System.out.println("\n--- Banking System ---\n1. Check Balance\n2. Deposit\n3. Withdraw\n4. Transaction History\n5. Exit");
4747
System.out.print("Enter your choice: ");
4848
int choice = sc.nextInt();
49+
System.out.println("");
4950

5051
switch (choice) {
5152
case 1 ->
5253
accountService.checkBalance(account);
5354
case 2 -> {
54-
System.out.print("Enter amount to deposit: ");
55+
System.out.print("Enter amount to deposit: $");
5556
double depositeAmount = sc.nextDouble();
5657
accountService.deposit(account, depositeAmount);
5758
}
5859
case 3 -> {
59-
System.out.print("Enter amount to withdraw: ");
60+
System.out.print("Enter amount to withdraw: $");
6061
double withdrawAmount = sc.nextDouble();
6162
accountService.withdraw(account, withdrawAmount);
6263
}
6364
case 4 ->
6465
account.displayTransaction();
6566
case 5 -> {
66-
System.out.println("\n---Exiting---");
67+
System.out.println("---Exiting---");
6768
System.out.println("Thankyou for using our banking system " + account.getAccountHolderName() + "!");
6869
System.exit(0);
6970
}

src/account/Account.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ public abstract class Account {
1010
private double balance;
1111
private final List<Transaction> transactions = new ArrayList<>();
1212

13-
public Account(String name, double balance) {
13+
public Account(String name, double balance,String accountType) {
1414
this.accountHolderName = name;
1515
this.balance = balance;
1616
this.accountNumber = generateAccountNumber();
17-
System.out.println("\nAccount Number is " + accountNumber);
17+
System.out.println("\n" + accountType + " Account created successfully for " + name + "!");
18+
System.out.println("Account Number is " + accountNumber);
1819
System.out.println("Initial balance is " + balance);
1920
}
2021

@@ -43,7 +44,7 @@ protected void addTransaction(String type, double amount) {
4344
}
4445

4546
public void displayTransaction() {
46-
System.out.println("\nTransaction History for Account Number: " + getAccountNumber());
47+
System.out.println("Transaction History for Account Number: " + getAccountNumber());
4748
if (transactions.isEmpty()) {
4849
System.out.println("No transactions yet.");
4950
} else {

src/account/CurrentAccount.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
public class CurrentAccount extends Account {
44

55
public CurrentAccount(String name, double balance) {
6-
super(name, balance);
7-
System.out.println("Current Account created successfully for " + name + "!");
6+
super(name, balance,"Current");
87
}
98

109
@Override

src/account/SavingAccount.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
public class SavingAccount extends Account {
44

55
public SavingAccount(String name, double balance) {
6-
super(name, balance);
7-
System.out.println("Savings Account created successfully for " + name + "!");
6+
super(name, balance,"Savings");
87
}
98

109
@Override

0 commit comments

Comments
 (0)