CS 201 - Computer Science I - Spring 2004
Project 1
Loyola College >
Department of Computer Science >
CS 201 >
Projects >
Project 1
Due
Thursday, February 26th at 11:59pm.
Projects will be penalized 20% for each day after the due date.
Projects will not be accepted more than four days late.
Objectives
- to perform computations using assignment statements and expressions
- to apply Java's rules of type and precedence
- to use String objects and their methods
- to use functions from the Java Math class
- to write classes with constructors and methods that perform calculations
Introduction
A level-coupon bond is an investment that provides the investor with repeating yearly payments over a fixed period of time. These yearly payments are called coupons. At the end of this period of time, the bondholder receives a lump sum; this amount is referred to as the face value of the bond.
The formula for calculating the value of a bond is
where r is the discount rate expressed as a decimal
(so 0.01 for 1%), T is the number of payments that you will recieve, C is the amount of the coupon payment, and F is the face value of the bond.
Assignment
Write a program called BondCalculator that allows the user to
enter the face value of the bond and discount rate and displays
the value of the bond assuming yearly coupon payments over 20 years of 5% of the face value of the bond.
The user's input will look like $100000 @ 4 1/4%. For full
credit, make only the following assumptions about the input:
- there is no space between the '$' sign and the value;
- there are no comma separators in the value;
- there are no spaces from the beginning of the numerator through the
'%' sign;
- all numeric parts of the input are integers; and
- integer rates are given with a zero numerator (e.g. 4 0/4%).
The output should appear in a dialog box with a message like
The value is 109970.77435615206
(but check with a calculator to see what the correct number is for the
input given above).
For full credit, you must use a helper class called Bond
that holds the face value, coupon amount (assumed to be 5% of the face value for this assignment), discount rate, and term of the bond (assumed to
be 20 years for the purposes of this assignment). Your Bond class
should have
- fields for face value, coupon amount, rate, and term;
- a constructor that packages the face value, coupon amount, discount rate, and term
into an object; and
- a calculateValue method that calculates the value of the
formula given above and returns the result.
Grading
- 70% Execution. Partial credit will be granted depending on how
much progress you made towards the correct result.
- 20% Design. The design score is based on how easy it is to
follow the logic of your code, how well you avoided repetitive code,
the types you choose for your variables,
and how easy it would be to change your code if certain specifications
changed.
- 10% Style. Style includes comments, indentation, and choice of
variable and method names.
- Substantial progress must be made towards correct execution to
earn the points for design and style.
Submissions
Submit the source code for your Bond and
BondCalculator classes.