0% found this document useful (0 votes)
28 views3 pages

Java Account Management System

The document contains Java code for a banking application with classes for Account, CheckingAccount, and SavingsAccount. It allows users to create accounts, perform deposits and withdrawals, and manage account details including interest rates and overdraft limits. The main method facilitates user interaction to create accounts and execute transactions while displaying account information.

Uploaded by

edmonddantez71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Java Account Management System

The document contains Java code for a banking application with classes for Account, CheckingAccount, and SavingsAccount. It allows users to create accounts, perform deposits and withdrawals, and manage account details including interest rates and overdraft limits. The main method facilitates user interaction to create accounts and execute transactions while displaying account information.

Uploaded by

edmonddantez71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab Problems

Lab05

```javaimport [Link];import [Link];


class Account { private int id; private double balance; private double ann
ualInterestRate; private [Link] dateCreated;
public Account() { this(0, 0.0, 0.0); }
public Account(int id, double balance, double annualInterestRate) { this.
id = id; [Link] = balance; [Link] = annualIntere
stRate; [Link] = new [Link](); }
public int getId() { return id; } public void setId(int id) { [Link] = id; } publ
ic double getBalance() { return balance; } public void setBalance(double bal
ance) { [Link] = balance; } public double getAnnualInterestRate() { ret
urn annualInterestRate; } public void setAnnualInterestRate(double annualInt
erestRate) { [Link] = annualInterestRate; } public [Link].D
ate getDateCreated() { return dateCreated; }
public double getMonthlyInterestRate() { return annualInterestRate / 12 /
100; }
public double getMonthlyInterestAmount() { return balance * getMonthl
yInterestRate(); }
public void withdraw(double amount) { if (amount <= balance) {
balance -= amount; } }
public void deposit(double amount) { balance += amount; }}
class CheckingAccount extends Account { private double overdraftLimit;
public CheckingAccount(int id, double balance, double annualInterestRate,
double overdraftLimit) { super(id, balance, annualInterestRate); [Link]
erdraftLimit = overdraftLimit; }
public double getOverdraftLimit() { return overdraftLimit; } public void set
OverdraftLimit(double overdraftLimit) { [Link] = overdraftLimit; }
@Override public void withdraw(double amount) { if (amount <= getB
alance() + overdraftLimit) { setBalance(getBalance() - amount); } el
se { [Link]("Overdraft limit exceeded."); } }
@Override public void deposit(double amount) { double fee = amount

Lab Problems 1
* 0.01; setBalance(getBalance() + amount - fee); }}
class SavingsAccount extends Account { private int rewardPoints; private
double minimumBalanceRequirement;
public SavingsAccount(int id, double balance, double annualInterestRate, d
ouble minimumBalanceRequirement) { super(id, balance, annualInterestRa
te); [Link] = minimumBalanceRequirement;
[Link] = 0; }
public int getRewardPoints() { return rewardPoints; } public void setRewar
dPoints(int rewardPoints) { [Link] = rewardPoints; } public double
getMinimumBalanceRequirement() { return minimumBalanceRequirement; }
public void setMinimumBalanceRequirement(double minimumBalanceRequire
ment) { [Link] = minimumBalanceRequirement; }
public double getCreditBalance() { return getBalance() + rewardPoints;
}
@Override public void withdraw(double amount) { if (getBalance() - a
mount >= minimumBalanceRequirement) { setBalance(getBalance() - a
mount); } else { [Link]("Withdrawal denied – minimum
balance rule."); } }
@Override public void deposit(double amount) { double fee = amount
* 0.01; double netAmount = amount - fee; setBalance(getBalance() +
netAmount); rewardPoints += (int) (netAmount / 100); }}
public class Main { public static void main(String[] args) { ArrayList<Acc
ount> accounts = new ArrayList<>(); Scanner scanner = new Scanner(Sy
[Link]);
for (int i = 0; i < 4; i++) { [Link]("\n--- Creating Accoun
t " + (i+1) + " ---"); [Link]("Press (1) for Checking Accoun
t"); [Link]("Press (2) for Savings Account"); int choic
e = [Link]();
if (choice == 1) { [Link]("Enter Account ID: ");
int id = [Link](); [Link]("Enter Initial Balance: ");
double balance = [Link](); [Link]("Enter Ann
ual Interest Rate: "); double rate = [Link](); Sy
[Link]("Enter Overdraft Limit: "); double overdraft = scanner.n
extDouble(); [Link](new CheckingAccount(id, balan
ce, rate, overdraft)); } else if (choice == 2) { [Link]
("Enter Account ID: "); int id = [Link](); [Link].

Lab Problems 2
print("Enter Initial Balance: "); double balance = [Link]
(); [Link]("Enter Annual Interest Rate: "); double r
ate = [Link](); [Link]("Enter Minimum Balanc
e Requirement: "); double minBalance = [Link]();
[Link](new SavingsAccount(id, balance, rate, minBalance)); }
}
for (Account acc : accounts) { [Link]("\n--- Performin
g transactions for Account ID: " + [Link]() + " ---"); System.o
[Link]("Enter deposit amount: "); double depositAmt = [Link]
uble(); [Link](depositAmt); [Link]("Enter
withdrawal amount: "); double withdrawAmt = [Link]();
[Link](withdrawAmt); }
for (Account acc : accounts) { if (acc instanceof CheckingAccoun
t) { CheckingAccount ca = (CheckingAccount) acc; System.
[Link]("\nThis is a Checking Account"); [Link]("Acco
unt ID: " + [Link]()); [Link]("Current Balance: " + [Link]
tBalance()); [Link]("Annual Interest Rate: " + [Link]
alInterestRate()); [Link]("Monthly Interest Amount: " + c
[Link]()); [Link]("Overdraft Limit: "
+ [Link]()); } else if (acc instanceof SavingsAccount) {
SavingsAccount sa = (SavingsAccount) acc; [Link]("\nTh
is is a Savings Account"); [Link]("Account ID: " + [Link]
d()); [Link]("Current Balance: " + [Link]());
[Link]("Annual Interest Rate: " + [Link]());
[Link]("Monthly Interest Amount: " + [Link]
t()); [Link]("Credit Balance: " + [Link]());
} [Link](); } [Link](); }}```

Lab Problems 3

You might also like