Write a program called Q1.java, which reads a series of lines from standard input (the keyboard) until there are no more lines to read. Each line will hold 3 pieces information about an investment (type.lib.Investment), namely the symbol (like ".AB") for a stock (type.lib.Stock), the number of shares of that stock and finally the current value per share of that stock ("book value"). You may assume that each input line is well formed; i.e. you do not have to check whether there are indeed 3 items on each line or whether each is of the required type or whether the values are in an appropriate range.
Start with an empty portfolio (type.lib.Portfolio). For each line read, use the information in the line to create a new investment and add it to the portfolio. When all lines have been read, print out information about the portfolio as shown in the sample output below.
A complication: 2 or more lines may have the same stock symbol. If the portfolio already contains an investment with this stock, then this line is simply ignored - nothing new is added to the portfolio.
The output should conform to that in the sample run of a correct program shown below. Note that, in this sample run, the % sign is not part of the program output.
% % java Q1 For each investment, enter stock symbol, number of shares and price per share, whitespace separated. Enter one line per investment. .BC 10 100.00 .AK 300 25.3456 .KH 29 3.8765 .BC 20 50.00 .PT 200 1.25 .BC 20 400.00 .AL 10 25.99 My portfolio: NAME QUANTITY BOOK_VALUE BRAVO-CHARLIE Inc. 10 $100.00 ALPHA-KILO Inc. 300 $25.35 KILO HOTEL Ltd. 29 $3.88 PAPA of TANGO Company 200 $1.25 Compu-ALPHA & LIMA Corp. 10 $25.99 % %
Here (again) are the common APIs that you may access:
Here is the command to submit your work
(further details regarding the submit command can also be
obtained by
typing man submit
Once again, you are encouraged to submit
regularly.
Newer submissions overwrite older ones.
submit 1020 labtest2R7 Q1.java