From ab8e5196723b01e8d0d3135cfda593f901c0f0c4 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 14 Sep 2024 09:33:00 +0530 Subject: [PATCH] Update OOP/Java/Lab/Week6/Account/AccountManagement.java --- .../Lab/Week6/Account/AccountManagement.java | 145 +++++++++++------- 1 file changed, 86 insertions(+), 59 deletions(-) diff --git a/OOP/Java/Lab/Week6/Account/AccountManagement.java b/OOP/Java/Lab/Week6/Account/AccountManagement.java index 4874902..5056833 100644 --- a/OOP/Java/Lab/Week6/Account/AccountManagement.java +++ b/OOP/Java/Lab/Week6/Account/AccountManagement.java @@ -1,76 +1,103 @@ -interface Sports { - int getNumberOfGoals(); - String dispTeam(); -} +// Account class +class Account { + private String customerName; + private int accountNumber; + private double balance; + private String accountType; -class Hockey implements Sports { - - private int goals; - private String team; - - public Hockey(int goals, String team) { - this.goals = goals; - this.team = team; + public Account(String customerName, int accountNumber, double balance, String accountType) { + this.customerName = customerName; + this.accountNumber = accountNumber; + this.balance = balance; + this.accountType = accountType; } - public int getNumberOfGoals() { - return goals; + public void deposit(double amount) { + balance += amount; } - public String dispTeam() { - return team; + public void withdraw(double amount) { + balance -= amount; + } + + public double getBalance() { + return balance; + } + + public String getAccountType() { + return accountType; } } -class Football implements Sports { +// SavingsAccount class +class SavingsAccount extends Account { + private double interestRate; - private int goals; - private String team; - - public Football(int goals, String team) { - this.goals = goals; - this.team = team; + public SavingsAccount(String customerName, int accountNumber, double balance, double interestRate) { + super(customerName, accountNumber, balance, "Savings"); + this.interestRate = interestRate; } - public int getNumberOfGoals() { - return goals; + public void computeInterest() { + double interest = balance * interestRate / 100; + deposit(interest); } - public String dispTeam() { - return team; - } -} - -public class SportsMatch { - - public static void main(String[] args) { - Hockey team1 = new Hockey(3, "India"); - Hockey team2 = new Hockey(2, "England"); - - Football team3 = new Football(2, "AFC Richmond"); - Football team4 = new Football(1, "West Ham United"); - - System.out.println("Hockey Match:"); - displayWinner(team1, team2); - - System.out.println("\nFootball Match:"); - displayWinner(team3, team4); - } - - public static void displayWinner(Sports team1, Sports team2) { - System.out.println( - team1.dispTeam() + " goals: " + team1.getNumberOfGoals() - ); - System.out.println( - team2.dispTeam() + " goals: " + team2.getNumberOfGoals() - ); - - if (team1.getNumberOfGoals() > team2.getNumberOfGoals()) { - System.out.println("Winner: " + team1.dispTeam()); - } else if (team2.getNumberOfGoals() > team1.getNumberOfGoals()) { - System.out.println("Winner: " + team2.dispTeam()); + public void withdraw(double amount) { + if (amount > getBalance()) { + System.out.println("Insufficient balance"); } else { - System.out.println("It's a tie!"); + super.withdraw(amount); } } } + +// CurrentAccount class +class CurrentAccount extends Account { + private double minimumBalance; + private double serviceTax; + + public CurrentAccount(String customerName, int accountNumber, double balance, double minimumBalance, double serviceTax) { + super(customerName, accountNumber, balance, "Current"); + this.minimumBalance = minimumBalance; + this.serviceTax = serviceTax; + } + + public void checkMinimumBalance() { + if (getBalance() < minimumBalance) { + withdraw(serviceTax); + System.out.println("Service tax imposed"); + } + } + + public void withdraw(double amount) { + if (amount > getBalance()) { + System.out.println("Insufficient balance"); + } else { + super.withdraw(amount); + checkMinimumBalance(); + } + } +} + +// Main function +public class AccountManagement { + public static void main(String[] args) { + SavingsAccount saurabhAccount = new SavingsAccount("Saurabh", 1234, 10000, 5); + CurrentAccount akhilAccount = new CurrentAccount("Akhil", 5678, 5000, 1000, 500); + + saurabhAccount.deposit(5000); + System.out.println("Saurabh's balance: " + saurabhAccount.getBalance()); + saurabhAccount.computeInterest(); + System.out.println("Saurabh's balance after interest: " + saurabhAccount.getBalance()); + saurabhAccount.withdraw(2000); + System.out.println("Saurabh's balance after withdrawal: " + saurabhAccount.getBalance()); + + akhilAccount.deposit(2000); + System.out.println("Akhil's balance: " + akhilAccount.getBalance()); + akhilAccount.withdraw(3000); + System.out.println("Akhil's balance after withdrawal: " + akhilAccount.getBalance()); + akhilAccount.checkMinimumBalance(); + System.out.println("Akhil's balance after checking minimum balance: " + akhilAccount.getBalance()); + } +} \ No newline at end of file