Project 1 – Simple GUI Application Calculating Interest

advertisement
Project 1 – Simple GUI Application Calculating Interest
This project is intended to review the concepts of basic application development using C# and
Visual Studio. It also introduces the use of methods. You need information in chapters 1-6 of the
text to do this project.
Operation
The user enters the starting amount, interest, and
number of years. When the “calculate” button is
pressed, the amount at the end of the time period is
calculated and displayed.
Interest is compounded annually. Compound interest
is interest which is calculated not only on the initial
principal but also the accumulated interest of prior
periods.
If the user holds the mouse over the End Amount box,
all of the boxes are cleared.
The program terminates when the “Exit” button is
pressed.
Specifications
The title of the window is “Interest Calculator”. Use the image on this page as a guide for the
layout of the GUI.
The text boxes should be named: txtStartAmount, txtInterest, txtYears, and
txtEndAmount. txtEndAmount box should be non-editable. (The ReadOnly property of
the End Amount box should be set to true.)
Write the following method to calculate the interest:
private decimal multiYearInterest (decimal, decimal, int)
The method has three parameters:



amount – a non-negative decimal which is the amount
at the start of the period
interest – a decimal >0 and <1 which is the
interest rate
years – an int which must be >0 and <100
The method returns a decimal with the total amount at the end of the period of years.
If there is an error, the method returns -1m.
In the method, define a decimal called moneySoFar which is set to the amount
parameter value initially. moneySoFar should be used to accumulate the amount with
interest added, one year at a time.
Validate amount to assure that it is greater than 0. Validate interest to assure that it is
>0 and <1. Validate years to assure that the number is >0 and <100. Return -1m is
the validation fails.
To calculate the total amount at the end of the period, use a loop. The loop should be
repeated once for each year. In the loop multiply moneySoFar by the interest
and add the result to moneySoFar.
Complete the method responding to the Calculate_Click event:
This method will have to convert the data entered in the txtStartAmount and
txtInterest boxes to decimal and the txtYears box to int. Check for
non-numeric characters in the TextBoxes using try and catch. Popup a MessageBox
with an error message if non-numeric characters are present and bypass the calculation.
Use:
MessageBox.Show(“Text”);
The method should call multiYearInterest to do the calculation with the
converted data. The returned value then has to be converted to a String and stored in the
txtEndAmount box. If multiYearInterest returns a negative number, then
popup a MessageBox indicating that the data values are either negative or too high.
Complete the method responding to the Exit_Click event, exiting the application.
Set the MouseHover event of txtEndAmount to call a method if the mouse is held over the
txtEndAmount box. In this method, clear the txtStartAmount, txtInterest, and
txtYears boxes.
Be sure to document your program by providing comments. Use the example on page 75 of the
text as a guide. Be sure your documentation is meaningful to someone maintaining your
program. Don’t just translate C# statements to English. What does each part of the program
do?
Submitting the project
Follow the instructions in the syllabus for submitting projects. Be sure you submit the
project correctly.
Grading
GUI component definition
Components named correctly
GUI layout
multiYearInterest method defined and used correctly
amount, interest, and years validated correctly
Loop and calculation correct
Exit Button functions correctly
Mouse Hover functions correctly
Documentation__
_______________ ________________
15%
10%
15%
10%
10%
10%
10%
10%
10%____
Total
100%
Download