The debugger can help you learn how classes and objects work. In this exercise we will debug the Ch. 8 "Stock" Case Study example. This program tracks purchases of two stock investments. To download the example:
Stock.java and StockMain.java.
Right-click each file name and Save the Link in the same folder you use for lab work.
StockMain.java in jGRASP to see that it works.
continued on the next slide...
System.out.print on line 53, and debug the program.
First stock's symbol: AMZN How many purchases did you make? 2 1: How many shares, at what price per share? 50 35.06 2: How many shares, at what price per share? 25 38.52
currentStock object? totalShares |
75 |
|
totalCost |
2716.0 |
continued on the next slide...
Stock object's methods.
Your program should still be stopped.
Set a new stop at the return on line 29 of Stock.java.
getProfit on the Stock and hit your stop point.
What is today's price per share? 37.29
this) 's fields, and the variable marketValue ?
symbol |
"AMZN" |
|
totalShares |
75 |
|
totalCost |
2716.0 |
marketValue |
2796.75 |
continued on the next slide...
for loop on lines 42-50 of StockMain, and Resume
Second stock's symbol: INTC How many purchases did you make? 3 1: How many shares, at what price per share? 15 16.55 2: How many shares, at what price per share? 10 18.09 3: How many shares, at what price per share? 20 17.05 What is today's price per share? 17.82
purchase, what are the field values of currentStock?
| field | after 1st purchase | after 2nd | after 3rd |
|---|---|---|---|
totalShares |
15 | 25 | 45 |
totalCost |
248.25 | 429.15 | 770.15 |