bmis209_programming_assignment_3_instructions.docx

BMIS 209

Programming Assignment 3 Instructions

Adapted from: Deitel & Deitel (2011). Visual C# 2010 How to Program (4th ed.). Pearson Education, Inc.

Write a recursive method called Power(base, exponent) that, when called, returns base exponent .

For example, Power ( 3, 4 ) = 3 * 3 * 3 * 3.

Assume that exponent is an integer greater than or equal to 1. The recursion step should use the relationship:

base exponent = base * base exponent – 1

The terminating condition occurs when exponent is equal to 1 because

base 1 = base

Incorporate this method into an application that enables the user to enter the base and exponent.

Requirements:

In the Main() method, declare three arrays of long data types: baseNumbers, exponents, and results. Each array should be created to hold exactly 5 members.

Using a FOR loop, populate the baseNumbers array with random integers between 1 and 50 and populate the exponents array with random integers between 1 and 10. Use a random number generator to create these random numbers.

Using another FOR loop, call the Power method, passing it a member of the baseNumbers array and a member of the exponents array for each iteration of the loop. Store the returned values in the results array.

The Power method should use the algorithm described above and MUST be recursive, taking two longs as arguments and returning a long data type.

Create another method called PrintArrays that takes as arguments the three arrays you created above and returns void. The method should print a header as “Base”, “Exponent”, and “Result” with each word separated with a single tab character. Using a FOR loop, iterate over each array using the GetUpperBound method to determine the condition for which the loop terminates. For each iteration of the loop, print out the base, exponent, and result from each array under the appropriate column headings. (Hint: You may need to use one or more tabs to separate the data values to make them line up with the headers above.)

The Main() method should call the PrintArrays method, passing in the three arrays as arguments.

Your output should resemble the example below:

Programming Assignment 4 Instructions

Adapted from: Deitel & Deitel (2011). Visual C# 2010 How to Program (4th ed.). Pearson Education, Inc.

Create a class called SavingsAccount. Use a static variable called annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance. Provide static method setAnnualInterestRate to set the annualInterestRate to a new value. Write an application to test class SavingsAccount. Create three savingsAccount objects, saver1, saver2, and saver3 with balances of $2,000.00, $3,000.00, and 0.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest and display the new balances for both savers. Then set the annualInterestRate to 5%, calculate the next month’s interest and display the new balances for both savers.

Technical Requirements:

Create SavingsAccount class with static variable annualInterestRate and private instance variables savingsBalance (double) and savingsAccountName (string).

Create a mutator method to set the savingsAccountName. Call this method setSavingsAccountName. The method should take a string argument and return void.

Create an accessor method to retrieve the savingsAccountName. Call this method getSavingsAccountName. The method should take no arguments and return a string (i.e. the savingsAccountName).

Create a mutator method to set the savingsBalance. Call this method setSavingsBalance. The method should take a double argument and return void.

Create an accessor method to retrieve the savingsBalance. Call this method getSavingsBalance. The method should take no arguments and return a double (i.e. the savingsBalance).

Include two constructors. The first takes no arguments and sets the savingsBalance variables to zero and sets the savingsAccountName to an empty string by calling the second (i.e. two argument) constructor with 0 and an empty string. The second constructor takes one double argument (the savingsBalance) and one string argument (the savingsAccountName), and sets the savingsBalance by calling the setSavingsBalance method and setsavingsAccountName method, respectively.

Create CalculateMonthlyInterest method with formula. The method should return void.

Create setAnnualInterestRate method to take a double argument representing the annualInterestRate and return void.

Create PrintSavingsAccount method to display the savingsBalance, savingsAccountName, and annualInterestRate for an object. Use the output shown below as a guideline for the display.

Create a separate class called SavingsAccountTest, which contains the Main() method.

In the Main() method, create three savingsAccount objects called saver1, saver2, and saver3. Initialize saver1 and saver2 with the balances listed above and the names “Saver_One” and “Saver_Two”, respectively. Do not initialize saver3 with anything. Instead, create the object by invoking its zero-argument constructor, which will initialize its balance to 0 and its name to an empty string.

In the Main() method, call setAnnualInterestRate to set the interest rate to 4%.

Next, call the setSavingsAccountName for saver3 to set its name to “Saver_Three”. Then, call the setSavingsAccountBalance for saver3 to set its balance to $50,000.

Print the results by calling PrintSavingsAccount for each object.

Next, call the CalculateAnnualInterestRate method for all three saver objects.

Print the results again by calling PrintSavingsAccount for each object.

Next, change the annualInterestRate to 5% by calling the setAnnualInterestRate method.

Print the results again by calling PrintSavingsAccount for each object.

Page 1 of 4