Comp 110L ?? March 2011

Putnam

Lab Project 6 ( Individual Project)

60 points

Instructions: This must be your own work, do not request help from, nor provide help to, your neighbors. Below are four possible candidate projects, i.e., specification documents.

You have some choice in selecting which ones to implement! The fourth project may be implanted for extra credit. The individual projects should be labeled as Project 6a, 6b, 6c & 6d.

If you are a Business Major of any kind you must do projects 6a and 6b. You have a choice of doing either 6c or 6d for the third project. You may choose to do the last remaining project for extra credit.

If you are in the School of Engineering or are a pre-computer science or pre-engineering student you must do 6c and 6d. You have a choice of doing either 6a or 6b for the third project. You may choose to do the last remaining project for extra credit.

If you are in the School of Science or are a Math Major you must choose either 6a or 6b and also choose either 6c or 6d. You may choose to do either of the remaining problems for the third project. You may choose to do the last remaining project for extra credit.

If you are some other major, see me for direction as to which projects you may choose.

The projects should have a cover sheet containing the following information

  • Project #6: Classes, Objects & Arrays
  • < list of projects submitted, e.g., 6a, 6c, 6d>
  • <extra credit 6b>
  • Section # <number>, i.e., Section 14201
  • Programmer: <name>
  • Date: <date submitted>

For instance each project submitted should contain header information such as the following

  • Project #6a: Financial Tsunami
  • extra credit
  • Section # <number>, i.e., Section 14201
  • Programmer: <name>
  • Date: <date submitted>
  • Description: <short statement of what the program will accomplish> embedded at the top of your program.

The selected projects should be sorted by the project numbers 6a, 6b, 6c, 6d with the proviso that the extra credit project should be place at the end of the sort regardless of its project number. The cover sheet should be stapled on top of the batch of subprojects.

Each file should be saved as, e.g., Project6a<your_last_name>, hence the main Class should also be labeled as Project6a<your_last_name>, e.g., if I were writing the program, I would have to label my main Class & file as Project6aPutnam.

All projects have to be signed off by the instructor or the lab assistant before submission.
Project 6a20 points

Banks lend money to each other and as we have seen in recent times, they may, in difficult economic circumstances, not be able to pay back the loan. A banks total assets are its current balance plus its loans to other banks. Below is a graph showing five banks and their loans to other banks. The banks are labeled in the nodes, i.e., circles, as bank 0, bank 1, … , bank 4. Each banks current balance, in millions, is shown next to the circle, i.e., 25, 125, … , 181. The directed edge, i.e., arrow, from node 1 to node 2 indicates that bank 1 loaned 40 million to bank 2.

If a bank’s total assets are under a certain limit, the bank is unsafe; the money it borrowed cannot be returned to the lender, hence the lender cannot count the loan in its total assets. Consequently, if the lender’s total assets are under the limit, the lender may be unsafe!

Write a program to locate all the unsafe banks. The program input is as follows:

  1. Input the number of banks to include in the graph, e.g., n
  1. Input the amount of assets, in millions, required for a bank to be liquid, i.e., the minimum total assets for a bank to be safe. (All banks in this program will have the same limit; in actuality, each bank would have a percentage of the total assets computed as part of determining it liquidity.) Remark: Input 345 to indicate 345,000,000.
  1. The next n input lines describe the information pertaining to the n banks from bank ID 0 to bank ID n-1. The first number in the line is the bank’s balance, the second number indicates the number of banks that borrowed money from the bank, the rest are pairs of two numbers. Each pair consists of the borrower’s ID and the amount borrowed.

For example to implement the graph given above, input the number of banks, i.e., nodes 5 followed by the amount required for liquidity, 201 (million).

Bank 0 has assets of 25.0, it has loaned to two banks;

bank 1 has borrowed 100.5 bank 4 has borrowed 320.5

Bank 1 has assets of 125.0, it has loaned to two banks;

bank 2 has borrowed 40.0 bank 3 has borrowed 85.0

etc.

5201.0

(bank 0)25.021100.54320.5

(bank 1)125.022 40.03 85.0

(bank 2)175.020125.03 75.0

(bank 3) 75.010125.0

(bank 4)181.012125.0

For the graph given above, the total assets of bank 3 are 75 + 125 < 201 hence bank 3 is unsafe. Bank 3 unsafe  total assets of bank 1 are 125 + 40 < 201 hence bank 1 is also unsafe.

The output should be

Unsafe Banks: 1, 3

Safe Banks: 0, 2, 4

Hint: use a 2-dimensional arrayborrowers to represent loans.

borrowers[ i ][ j ] indicates the loan that bank i made to bank j

once bank j becomes unsafe, borrowers[ i ][ j ] should be set to zero

Project 6b20 points

  1. Design a class named Account that contains the following:
  • Private int data field named account_ID with a default value of zero
  • Private double data field named accountBalance for the account with a default value of zero
  • Private double data field named annualInterestRate that stores the current interest rate with a default value of zero
  • Private Date data field named dateCreated that stores the date when the account was created including the time of day (hour, minutes, seconds, milliseconds)
  • A no-arg constructor that a default account
  • A constructor that creates an account with a specified account_ID and initial accountBalance
  • Accessor and mutator methods for account_ID, accountBalance, annualInterestRate
  • Accessor method for dateCreated
  • A method called getMonthlyInterestRate( ) that returns the monthly interest rate
  • A method called withdraw( ) that withdraws a specified amount from the account specified
  • A method called deposit( ) that deposits a specified amount to the account specified
  1. Draw the UML diagram for the class.
  2. Implement the class.

Write a test program that creates an account with account_ID of 1122, an account balance of $20,500 and an annual interest rate of 4.5%. use the withdraw( ) method to withdraw $2,500 and use deposit( ) method to deposit $3,000. Print the balance, the monthly interest rate and the date the account was created.

Create an array of 10 reference variables of the type Account. Create a test program that will randomly populate 10 instances of the class, i.e., will create 10 objects of type account with each object assigned to one of the reference variables. Withdraw a random amount from each object, deposit a random amount to each account and then print the balance, the monthly interest rate and the date the account was created down to the milliseconds.

Project 6c

  1. Design a class called QuadraticEquation for a quadratic equation ax2 + bx + c = 0 which contains the following:
  • Private data fields a, b, and c that represent the coefficients
  • A constructor used to initialize a, b, and c
  • A method named getDiscriminate( ) that returns the discriminate b2 – 4ac
  • Methods named getRoot1( ) and getRoot2( ) for returning the two roots of the equations and

If the discriminate then the equations above return the computed values otherwise they return zero.

  1. Draw the UML diagram for the class.
  2. Implement the class
  3. Write a test program that prompts the user to enter values for the coefficients a, b, & c and which displays the result based on the discriminate. i.e.,

if the discriminate then display the two roots r1 & r2

if the discriminate then display the one root r1

if the discriminate then display “the equation has no roots”

  1. For test data use the examples delineated in Liang page 106 exercise 3.1

Project 6c

  1. Design a class named LinearEquation for a 2 x 2 system of linear equations

and

where

and

  1. The class contains
  • Private data fields for a, b, c, d, e, & f
  • A constructor with arguments for a, b, c, d, e, & f
  • Six distinct get methods one for each of the arguments a, b, c, d, e, & f
  • A method call isSolvable( ) that returns

true if ad – bc 0and false ifad – bc == 0

  • Methods getX( ) and getY( ) that return the solutions for the equation as per the formulae given above
  1. Draw the UML diagram for the class.
  1. Implement the class
  2. Write a test program that prompts the user to enter values for a, b, c, d, e, & f.

If ad – bc 0 then display the results as per getX( ) and getY( ).

If ad – bc == 0 then display “the equation has no solution”

  1. For test data use the examples delineated in Liang page 107 exercise 3.3