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

Assignment 1

notes

Uploaded by

arutfb
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)
10 views

Assignment 1

notes

Uploaded by

arutfb
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
You are on page 1/ 4

COMP102P2 Assignment 1

Due 27 September 2023

In this assignment you will create classes and work with objects that simulate a Banking environment. You
are expected to create a Bank class, a BankAccount, an AccountOwner class and a BankingApplication class.
The details are outlined below.

Common things amongst the classes to be created:


• all attributes for each class must be private
• all attributes must each have a setter and a getter methods
• all classes must have a default constructor and a parameterized constructor (with all the class
attribtes)
• if a setter method is used to initialize/update a value which is an object, it must only proceed to set it
if its not null, in the case of a deviation an exception must be thrown and prevent the object from
being insantiated.
• All attributes of type int or double should be non negatives when an object is insantiated, in the case
of a deviation an exception must be thrown and prevent the object from being insantiated.

The AccountOwner class will have the following:


• name – String type (attribute)
• age – int type (attribute)
• income – double type (attribute)
• constructors (2)
• setters & getters for all attributes (they should correspond with the common conditions placed
above)
• a toString() method that will returns the values of the AccountOwner’s attributes as a comma
seperated concatenated string(this method will be used in another method, see the full output
example towards the end)

The BankAccount will have the following:

• an accountNumber – int type (attribute)


• a balance – type double(attribute)
• and accOwner - type AccountOwner (this is a user defined type)
• a method named deposit which recieves an amount(type double) and returns true if the deposit was
successful, false othwerwise. A deposit is successful if the amount being deposited is greater than 0.
The method should print the message Deposit successful if it was. Otherwise it should print, Deposit
failed.
• a method named withdraw which recieves an amount(type double) and returns true if the
withdrawal was successful, false othwerwise. A withdrawal is successful if the amount being
withdrawn at most the avaialable balance. The method should print the message Withdrawal
successful if it was. Otherwise it should print, Insufficient funds.
• The setter for the accountNumber must ensure that the value must have 10 digits and not begin with
a zero.
• The initial balance must be at least R200.00, that is when the object is being instantiated, the setter
method for the balance attribute should address this
• A toString( ) method that combines the output from the toString method of the AccountOwner and
the balance associated with the account (use the attached output as a guide).
• Setters & getters that conform to the common rules and implement more rules where specifed.
• A default and a parameterized constructor

The class named Bank will have the following:


• accounts - an ArrayList of BankAccount objects (this is an atttribute of the Bank class)
• a method named addAccounts that takes a number n(where n in an integer) and requests details for
n accounts from the user and adds them into the accounts ArrayList of BankAccounts. The method
should not return anything (void). The accountNumber for each account will be its index in the
ArrayList.
• A method named findAccountByName that recieves a string which is the name of the account’s
owner and returns an arrayList of BankAccount objects from the accounts ArrayList in which the
name of the account owner is the same as the one being searched.
• A method named wealthiest that takes an integer n and returns an array (not ArrayList) of the
BankAccount objects where the balance ranks with the highest n balances found in all accounts of
the accounts ArrayList. In the case of a tie in bank balances, choose the account whose owner has a
higher income. Assume that there will be no further ties in the income atribute’s value.
• A method named toReview returns an ArrayList of AccountOwners whose BankAccounts have a
balance below the average balance of all bank accounts in the accounts but the quotient of the
income to the balance (income / balance) is above 5 for that account owner.

The BankingApplication class must have a main method (the only class that should have a main method)
and it must implement the Banking activities where all classes will be used (directly or indirectly).

Refer to the example output to have an idea of how your program is expected to behave in some cases. Not
all instances of the program’s behaviour are explicitly shown in the sample output. It will help to read all
requirements carefully and make sure that your solution addresses all the requirements. Feel free to make
your own input prompts where not advised explicitly. Ensure that all methods are tested(called in another
method or in the main, depending on the context) You are given some flexibility on some things. e.g., in
option 5 in the menu (see image outputs) choose how to provide the user with only two nested options after
they choose option 5, then call the relevant method for each nested option. Both the options should allow for
the wealthiest and toReview methods to be called.
Only submit *.java files in a *.zip file named with your student number.

You might also like