0% found this document useful (0 votes)
21 views4 pages

Project 2... 0

Uploaded by

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

Project 2... 0

Uploaded by

ahmeed101700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

COMP2108 – Object Oriented Programming

Term Project
Student Name: Mohammed Ashibli Student ID: 210985 .

Team Members 1. Ahmed Alfarsi Student ID: 210393 .


Team Members 2. Suhail Albaraami Student ID: 210399 .
Team Members 3. Saud almuqbali Student ID: 201608 .

Class Implemented (name and what it does):

Ahmed did the first task . (class Accont)

Suhail did the second task.(Saving accont class)

Mohammed did the third task.(currint account )

Saud did the fourth task. (main class)

Full code :

class Account {
private int accountNumber;
private String accountHolderName;
private double balance;

public Account(int accountNumber, String accountHolderName, double balance) {


this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.balance = balance;
}

public int getAccountNumber() {


return accountNumber;
}

public String getAccountHolderName() {


return accountHolderName;
}

public double getBalance() {


return balance;
}

public void setBalance(double balance) {


this.balance = balance;
}

public void deposit(double amount) {

public void withdraw(double amount) {

public void checkAccount() {

public final String toString() {


System.out.println("Account Number: " + accountNumber);
System.out.println("Account Holder: " + accountHolderName);
System.out.println("Balance: " + balance);
return null;
}
}

class SavingsAccount extends Account {


COMP2108 – Object Oriented Programming
Term Project
private double interestRate;

public SavingsAccount(int accountNumber, String accountHolderName, double balance, double interestRate) {


super(accountNumber, accountHolderName, balance);
this.interestRate = interestRate;
}

public double getInterestRate() {


return interestRate;
}

public void setInterestRate(double interestRate) {


this.interestRate = interestRate;
}

@Override
public void withdraw(double amount) {

double minimumBalance = 10.0;

if (getBalance() - amount >= minimumBalance) {


setBalance(getBalance() - amount);
System.out.println("Withdrawal successful. New balance: " + getBalance());
} else {
System.out.println("Withdrawal failed. Insufficient funds.");
}
}
}

class CurrentAccount extends Account {


private final double overdraftLimit = 10.0;

public CurrentAccount(int accountNumber, String accountHolderName, double balance) {


super(accountNumber, accountHolderName, balance);
}

@Override
public void withdraw(double amount) {

if (getBalance() - amount >= -overdraftLimit) {


setBalance(getBalance() - amount);
System.out.println("Withdrawal successful. New balance: " + getBalance());
} else {
System.out.println("Withdrawal failed. Exceeds overdraft limit.");
}
}
}

public class Main {


public static void main(String[] args) {

SavingsAccount savingsAccount = new SavingsAccount(210393, "Ahmed alfarsi", 1527.585, 0.02);


CurrentAccount currentAccount = new CurrentAccount(210985, "Mohammed alshibli", 2696.0);

savingsAccount.deposit(50.0);
savingsAccount.withdraw(20.0);
savingsAccount.checkAccount();
savingsAccount.toString();

System.out.println();

currentAccount.deposit(100.0);
currentAccount.withdraw(250.0);
currentAccount.checkAccount();
currentAccount.toString();
}
}
COMP2108 – Object Oriented Programming
Term Project

Explanation of your code (vairables, methods, overrides):

CurrentAccount Class (Inheritance):

Additional Attributes:

private final double overdraftLimit

Additional Methods:

Override withdraw(double amount) to allow overdrafts up to the specified limit

The CurrentAccount class also inherits from the Account class, introducing an overdraft limit attribute.
The withdraw method is overridden to permit overdrafts up to the specified limit.

Design Decisions:

Encapsulation:

All attributes in the Account, SavingsAccount, and CurrentAccount classes are private, ensuring proper
encapsulation. Access to these attributes is provided through getters and setters.

Abstract Methods:

The use of abstract methods in the Account class enforces a common interface for all account types.
Subclasses must provide their implementation for deposit, withdrawal, and checking account balance.

Final Methods:
COMP2108 – Object Oriented Programming
Term Project
The toString() method is marked as final in the Account class to prevent subclasses from overriding it.
This decision is made to maintain consistency in printing account details across all subclasses.

Minimum Balance Requirement:

In the SavingsAccount class, the withdraw method incorporates a minimum balance requirement to
ensure that the account always maintains a specified minimum balance.

Overdraft Limit:

The CurrentAccount class introduces an overdraft limit attribute, and the withdraw method is
overridden to allow overdrafts up to the specified limit. This design decision provides flexibility for
different types of accounts with varying features.

Any changes you made apart from the given (vairables, methods, overrides):

No changes.

You might also like