Download Computer Technology MSIS 22:198:605 Homework 2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Computer Technology MSIS 22:198:605
Homework 2
Instructor: Farid Alizadeh
Due Date: Monday October 14, 2002 by midnight
Submission: by e-mail (See below for detailed instructions)
last updated on October 5, 2002
Rules:
Please note the following rules:
1. Assignments should be e-mailed on or before the day and time they
are due.
2. Late submission will result in loss of 25% of the points.
3. very important: It is not possible to pass this course if you miss more
than one programming assignment regardless of your scores in other
assignments or exams.
4. All programming projects should be submitted by e-mail. Put all the files
including all the .java and all the .class and possible input or output
files in a single .zip file. The file name should be in the following format:
LastnameFirstnameHWno.zip. For example a student
named Sally Jones submitting Home work number 2 will have
her file named: JonesSallyHW2.zip. To get a zip archive file you can
for instance download the PkZip software form http://www.pkzip.com.
You should e-mail your code as an attachment to me at
[email protected], with subject line MSIS605 HW2, exactly. Any deviation from this may result in delay in grading your home
work.
5. Every class that you define must be started with a comment that indicates
your name, student ID number, the home work number and your e-mail
address. For instance if Sally Jones is turning home work number 2 and
as part of her home work he has defined a class named investment then
this class will look something like this:
class investment{
1
MSIS 605, Fall 2002
Homework 2
//
//
//
//
Due date: 10/14/02
Name: Sally Jones
Student ID: 123456789
Home work no 2
e-mail: [email protected]
.... the rest of the program ...
}
2
MSIS 605, Fall 2002
Homework 2
Due date: 10/14/02
Calculating investment parameters
The purpose of this home work is to build on your work from home work 1 and
design a program that reads information about various investment parameters
on line and calculates the desired parameter. The program contains two classes
each written in its own file. The first one is similar to the invest class you
wrote for home work 1 except that there should be no main method there.
The second class should contain the main method and a bunch of auxiliary
methods. The main method gets the form of its input argument the information
on the parameters that are known and information about the parameter to be
calculated and passes this information to other methods for processing.
(onlineInvest.java file.)
Program details
You should design two classes each in its own file.
The Investment class
The first class should be called investment and it should be written in a file
called investment.java. The investment class is similar to your invest class
in home work 1 with the following provisions:
1. All variables and methods should now be declared without the static
tag.
2. The main method should be removed form this class.
3. all fields such as fv, pv, r, etc. should be declared private. No object
should be allowed to access them directly.
4. For each of the fields pv, fv, r, pmt, n, and nPer write a modifier
method. For instance for pv a modifier method would be:
public void setPv(newPv){
pv=newPv;
}
You should write a similar method for each of the other fields mentioned.
This will be the only way outside objects can modify the fields inside the
investment class.
5. You should duplicate the getxxx() methods you wrote for the four variables fv, pv, pmt, nPer in home work 1, except that these methods now
should not only set their corresponding variables but also have to return
them. For instance the getFv() method should be changed as follows:
3
MSIS 605, Fall 2002
Homework 2
Due date: 10/14/02
double getFv(){
// what ever code you have ....
fv = // the formula for fv here ...
return fv;
}
getPv, getNPer and getPmt should also be modified accordingly. (Remember for getNPer the return value should be int type.)
The onlineInvest class
The second class should be called onlineInvest and should reside in the onlineInvest.java
file. To understand how this method works you should first understand how it is
used. Suppose you need to calculate the future value (fv). You need to communicate this to the program and also give the values present value (pv), number
of periods per year (n), annual interest rate (r), periodic payment (pmt) and
duration of the loan in periods (nPer). Here is how the program will be called:
java onlineInvest fv pv 10000 r 0.05 n 12 nPer 36 pmt 0.0
This would mean that we want to calculate fv. In general the first entry is the
parameter we need to calculate. This is followed by other parameters and their
values. In this example pv=10000, r=5%, n=12, nPer=36 and pmt=0.0. The
order in which these parameters are entered is not important, except that the
parameter we wish to calculate must come first and each of the parameters must
come as a pair with their name followed by their values (pv 10000 for example).
In addition to the main method you should write five other methods:
1. void calcFv(String[] dat) This method creates an investment object
and using its setxxx methods it first sets the known parameters. Then it
will call its getFv() method to find the future value and prints it out.
2. void calcPv(String[] dat) This method creates an investment object
and using its setxxx methods it first sets the known parameters. Then it
will call its getPv() method to find the present value and prints it out.
3. void calcPmt(String[] dat) This method creates an investment object
and using its setxxx methods it first sets the known parameters. Then
will call its getPmt() method to find the periodic payment and it prints
it out.
4. void calcNper(String[] dat) This method creates an investment object and using its setxxx methods it first sets the known parameters.
Then will call its getNper() method to find the number of periods and it
prints it out.
5. void setParameter(String parameter, String dat) This method takes
two parameters. The first is a string containing one of "fv", "pv",
"pmt", "r", "n", "nPer". The second numeric is the String containing
digits; for instance ”1000”.
4
MSIS 605, Fall 2002
Homework 2
Due date: 10/14/02
I have prepared a template onlineInvest which can be found in onlineInvest.java.
I have written some of the code and I have asked you to write the rest of the
code. Please download this file and fill the missing code. You are responsible
for writing the investment class yourself though.
Useful reading
For this assignment the program is loosely patterned after the programs Stats.java
and onlineStats.java. It will be useful to review those again. Also you will
benefit a lot by reading chapter 2 sections 2.4 to 2.8.
5