0% found this document useful (0 votes)
24 views

CSC 2209 Object Oriented Programming 1

The document describes an Account class with methods to deposit, withdraw, and check the balance of an account. It then asks the reader to: 1. Create SavingsAccount and CurrentAccount subclasses that add additional attributes and override methods as needed. 2. Create a Bank class containing an array of Account objects including instances of Account, SavingsAccount and CurrentAccount. 3. Write a update method in the Bank class to iterate through accounts, add interest to savings accounts and send letters for overdraft current accounts.

Uploaded by

hordoya banik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

CSC 2209 Object Oriented Programming 1

The document describes an Account class with methods to deposit, withdraw, and check the balance of an account. It then asks the reader to: 1. Create SavingsAccount and CurrentAccount subclasses that add additional attributes and override methods as needed. 2. Create a Bank class containing an array of Account objects including instances of Account, SavingsAccount and CurrentAccount. 3. Write a update method in the Bank class to iterate through accounts, add interest to savings accounts and send letters for overdraft current accounts.

Uploaded by

hordoya banik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Quiz 2 CSC 2209 Object Oriented Programming 1 Time: 30Min

Name: ID:
public class Account
{
private double bal; //The current balance
private int accnum; //The account number

public Account(int a)
{
bal=0.0;
accnum=a;
}

public void deposit(double sum)


{
if (sum>0)
bal+=sum;
else
System.err.println("Account.deposit(...): "
+"cannot deposit negative amount.");
}

public void withdraw(double sum)


{
if (sum>0)
bal-=sum;
else
System.err.println("Account.withdraw(...): "
+"cannot withdraw negative amount.");
}

public double getBalance()


{
return bal;
}

public double getAccountNumber()


{
return accnum;
}

public String toString()


{
return "Acc " + accnum + ": " + "balance = " + bal;
}

public final void print()


{
//Don't override this,
//override the toString method
System.out.println( toString() );
}

}
Look at the Account class Account.java and write a main method in a different class to briefly experiment
with some instances of the Account class.
Quiz 2 CSC 2209 Object Oriented Programming 1 Time: 30Min
Name: ID:

 Using the Account class as a base class, write two derived classes called SavingsAccount and
CurrentAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have
an interest variable and a method which adds interest to the account. A CurrentAccount object, in addition
to the attributes of an Account object, should have an overdraft limit variable. Ensure that you have
overridden methods of the Account class as necessary in both derived classes.
 Now create a Bank class, an object of which contains an array of Account objects. Accounts in the array
could be instances of the Account class, the SavingsAccount class, or the CurrentAccount class. Create
some test accounts (some of each type).
 Write an update method in the bank class. It iterates through each account, updating it in the following
ways: Savings accounts get interest added (via the method you already wrote); CurrentAccounts get a letter
sent if they are in overdraft.

Hints:

 Note that the balance of an account may only be modified through the deposit(double) and
withdraw(double) methods.
 The Account class should not need to be modified at all.

You might also like