CST141 Project 1: Chapter 9
The Stock Class
-
In BlueJ create a new Java project named "project-1" with a class
Stock as per the instructions in the textbook for Exercise 9.2
(see above).
-
Though not clear from the text, the constructor should take two parameters,
one each to be assigned to the symbol and name
instance variables; additionally in the constructor assign default values
of zero (0) to the variables previousClosingPrice and
currentPrice
-
Although the text does not specify, there should be two set
methods, one each for the previousClosingPrice and currentPrice
instance variables; in both cases use an if statement to assure that
the value of both variables is zero (0) or greater
-
To calculate the percentage change in the getChangePercent
()
method, first subtract the previous closing price from the new current price and
then divide by the previous closing price. For example using the test values
in the textbook for previous closing price (34.5) and new current price (34.35),
the percent change should be approximately -0.004
-
To summerize, the Stock class, as per the instructions above, should have just
four (4) methods:
-
The Stock constructor with two (2) parameters that
initializes the four (4) instance variables
-
A set method for the previousClosingPrice
instance variable
-
A set method for the currentPrice
instance variable
-
The method getChangePercent that calculates and returns
the percent change from previousClosingPrice to
currentPrice
- Document the program by (10% deduction on your grade if these assigned comments are missing):
-
Including a comment statement that decribes the application's purpose, as well as
substituting your name (and the names of your teammates)
for the existing
@author
and the assignment due date
for the @version
comment that already exist at the top of the new class
-
Entering a comment before each method (including the constructor) to describe
its function
-
Draw the UML diagram for the class as specified in the textbook; it is suggested
that you do this before you begin to create the class
as this should make the coding much easier. However it is not necessary to
"Write a test program ..." as
we have not learned yet in class how to do that.
-
Students may work on all projects in teams of two or three,
and, if so, all students in the group must submit the same project to their own dropboxes
in Blackboard. In the text box's dropbox, as well as in the source code documentation
(comments), state the name(s) of the classmate(s) with whom you worked.
-
When all steps are finished, you will submit the "Stock.java"
file that is found in the "project-1" folder.
-
The completed project with a copy of the Stock class file (the .java file)
along with the UML diagram submitted electronically via attachments to a
Blackboard
dropbox is due to Prof. Struck by 11:59 p.m. on the date specified in the course outline.