## Question

Assume that the Certificates of Deposits (CDs) offered by various banks are compounded annually. The final value of the CD is computed using the following formula:

FinalValue = InitialDeposit * (1 + r)ᵗ,

where t is the number of years the CD is invested, and r is the interest rate in decimal form. If the interest rate is 4%, then r = 0.04.

Create a package named cs520.hw2.part1 and complete the following by writing the appropriate classes under this package.

Create a “procedural style” program that meets the requirements below. Create a class named BankingProceduralStyle and test the final value of two different CDs as specified below. BankA offers 3 year CDs with an interest rate of 4%. BankB offers 4 year CDs with an interest rate of 3%. You have $5000 to invest and considering the above two options. Use the variables for initial deposit, bank name, bank interest, and bank term (# of years) – one set of variables for the first CD and a different set of variables for the second CD.

a. Compute the final value of the CD from BankA and display the results to the console.

b. Compute the final value of the CD from BankB and display the results to the console.

c. Using the if-else construct, check which option is better in terms of the final values and display the results to the console.

A sample output with the values above is shown below. Note that your program should not hard code the input values in the calculations of the final value and should only use the variables in the calculations.

Part 2

Create a package named cs520.hw2.part2 and complete the following by writing the appropriate classes under this package.

Transform the procedural style computation of the previous problem into an object- oriented application. In order to do this, create two classes named BankCD and BankingObjectStyle as specified below.

a. The class named BankCD describes each CD offering and should have

- The instance (or member) variables – bankName (String), initialDeposit (integer), rate (double) and numberOfYears (integer).

- A single constructor that takes the name of the bank.

- The appropriate set methods for the above variables except the bank name.

- The appropriate get methods for all of the instance variables.

- The method getFinalValue, of type double, which returns the final value of this CD.

- The method printCDDetails, of type void, which displays the details of this CD to the console. This method should invoke the getFinalValue method as part of its output.

b. The class named BankingObjectStyle creates two CD objects and tests them as follows:

- In the main method, instantiate two objects of the type BankCD

named bank1CD and bank2CD.

- Perform the equivalent steps to the ones carried out in Part 1 by setting the appropriate values for the objects. Print the details of the two objects. Invoke the getFinalValue method for

comparing the two. The output should be the same as in Part 1.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package cs520.hw2.part1;// Beginning of BankingProceduralStyle class

public class BankingProceduralStyle

{

// Beginning of Main Method

public static void main(String[] args)

{

// Variables are declared and set

String banAName="BankA";

int banAYrs = 3;

double banADep = 5000;

double banARat = 4.00;

String banBName="BankB";

int banBYrs = 4;

double banBDep = 5000;

double banBRat = 3.00;

// Calculate the Bank A CD Final Value

double banACDFVal = banADep * Math.pow((1 + (banARat/100)), banAYrs);

// Display the Bank A CD information

System.out.printf("%s %s-year CD of %.2f at %.2f%% rate is worth $%.2f\n", banAName, banAYrs, banADep, banARat,banACDFVal);

// Calculate the Bank B CD Final Value

double banBCDFVal = banBDep * Math.pow((1 + (banBRat/100)), banBYrs);

System.out.printf("%s %s-year CD of %.2f at %.2f%% rate is worth $%.2f\n", banBName, banBYrs, banBDep, banBRat,banBCDFVal);

// Comparing and displaying the two Bank CDs final value difference results

if (banACDFVal>banBCDFVal)

{

// Prints out the result if the Bank A CD Final Value is greater than than Bank B CD Final Value

System.out.printf("%s's CD exceeds %s's CD by $%.2f",banAName,banBName, banACDFVal-banBCDFVal);

}...

By purchasing this solution you'll be able to access the following files:

Solution.zip.