Stock Portofolio

 

 

A few years ago, the major American stock exchangees began reporting stock prices as decimal values (i.e., dollars and cents), as is common practice in all other institutions.

 

Previously, however, – in a tradition dating back to the Spanish conquistadores - prices had been calibrated to the nearest eighth (or sixteenth, thirty-second, etc.) of a dollar.

 

This assignment is to write a class to represent a stock portfolio using the traditional measure, and another class that tests it.

 

 

I. The StockPortfolio Class

 

Instance variables of the class will include

 

1.         The name of the company

2.         The number of shares held

3.         The dollar portion of the stock price

4.         The eighths portion of the stock price

 

The class will have a constructor that initializes the instance variables of an object to arguments passed when the object is created.

 

Other methods of the class will include

 

1.        “Get” methods for each of the instance variables

2.        A method to modify the stock price.  This method will have 2 parameters:

·         The change in the dollar portion of the price

·         The change in the eighths portion of the price

3.        A method to compute and return the portfolio value as a decimal

 

 

II. The Test Class (aka: “Client Code”)

 

Your test class will contain statements to accomplish each of the following:

 

1.        Create a StockPortfolio object

2.        Call the “get” methods to access the object data (name, number of shares, dollars, eighths), and then print it

3.        Get and print the portfolio value as a decimal

4.        Modify the stock price

5.        Get and print the updated stock price

6.        Get and print the updated portfolio value


 

Here is some sample output (assuming the price change was +7 2/8):

 

     Company:   American VeebleFetzer, Inc.

 

     Shares Held: 100

 

     Opening Price per Share: 37 5/8

 

     Opening Portfolio Value: $3762.5

 

     Closing Price per Share: 44 7/8

 

     Closing Portfolio Value: $4487.5

 

 

III. Additional specifications:

 

1.         The instance variables for the dollars, eighths, and number of shares must be type int, and – as always - all instance variables must be declared private.

2.         Although your program must work for any reasonable data, use the data shown above (including the price change of 7 2/8) in the run you hand in.

3.         Include a comment block at the beginning of your program containing your name and section, the required (signed) affirmation, and a brief description of the problem.

 

 

 

 

 

 

For you to know:

F         For this assignment is it perfectly OK if your setNewPrice method results in an “improper” mixed number - i.e. the modified stock price has an eighths value >=8.  (This does not occur with the test data we are using).  However, extra credit if your setNewPrice can convert to a proper mixed number without using any decision-making statements of any kind.

 

 

Hosted by www.Geocities.ws

1