I imagine ChangeMaker.java would explain everything you need to know. But anyways...
Using your example "turn 48 11/8 into 49 3/8"
For now disregard the 48 and focus solely on the fractional component. How many dollars is 11/8? If you evaluate the fraction using "human" division there are 11.375 dollars in 11/8. But your class does not maintain decimal components it maintains two integers to represent whole dollars and eighths of a dollar. If you simplify the fraction into a mixed number you have 1 3/8, which is comparable to the format that your class maintains share prices in. dollar = 1 and eighths = 3, but how did we arrive at this conclusion. First we evaluate how many whole dollars are in 11/8. In Java if you divide two integers any non integer component (ie decimals) are thrown away, so 11 ÷ 8 = 1. Now how do we know how many eighths of a dollar we have in 11/8 that aren't part of a whole dollar? Like carteblanche said in his first post, mod basically gives you the remainder. So 11%8 will give you a result of 3. So by evaluating 11 ÷ 8 we have determined we have 1 whole dollar in 11/8 and by evaluating 11/%8 we determined we have 3/8 leftover. When you consider the $48 we have been ignoring thus far, you need to add the whole dollar and set eights = 3, so dollar = 48 + 1 = 49 and eighths = 3.
Using the example from above:
1. Closing Price per Share: 44 7/8
2. Change in Share Price: 4 4/8
3. Closing Price per Share: 49 3/8
At step 1. stockPortfolio.dollar = 44 and stockPortfolio.eighths = 7
On step 2. stockPortfolio.modifyStockPrice(4, 4) is called.
On Step 3. the expected values are stockPortfolio.dollar = 49 and stockPortfolio.eighths = 3, but being that your modifyStockPrice method is defined as:
Code
public void modifyStockPrice( int dollar, int eighths ) {
this.dollar += dollar;
this.eighths += eighths;
}
[/CODE]
The actual result is stockPortfolio.dollar = 48 and stockPortfolio.eighths = 11. To get the expected result, you need to evaluate how many eighths there are and convert them to dollars and add to dollar and set the remainder to eighths.