Changes to Oblig5 Precode - BUG FIX

Hi everyone (keep on reading, this is important)!

We were alerted about a bug on Piazza by a very attentive student (shoutout to him) which I have now corrected.
Basically the bug was that Oblig5Precode assumed that MAX_X and MAX_Y were actual max values for x and y, and not indexes in x[] and y[] where you would find the max values for x and y. So basically:

Oblig5Precode:
- MAX_X is the highest value in x[]
- MAX_Y is the highest value in y[]

Oblig5.java (the one I published):
- MAX_X is the index in x[] where you can find the highest value in x[]
- MAX_Y is the index in y[] where you can find the highest value in y[]

So the definition of MAX_X and MAX_Y would have to be the same in both Oblig5Precode and Oblig5, meaning that one of them would have to be changed:

If I changed the meanings in Oblig5.java - which I know a lot of you have based your sequential solutions on - a lot of you would have to make changes to your codes.
If I changed the meanings in Oblig5Precode.java all you would have to do would be to download the new Oblig5Precode.

For you to be able to avoid as much confusion and extra work as possible, I decided to opt for the second solution.

This means that you should replace your version of Oblig5Precode.java with the newest version which is on my Github: Precode

And you don't have to make any changes to your code for it to work. One thing you should do though to make the automatic sizing of the graph better is to also define MAX_Y in the same manner as MAX_X.

FYI: While debugging, I noticed another bug in Oblig5.java. The previous version assumed that there would always be a point below and above the first line drawn between MAX_X and MIN_X. This is not always the case and would occasionally result in a NullPointerException. You should review the changes I made here and make sure you don't make the same mistakes I did.


Feel free to contact me if you have any questions!

- Kim

Published Apr. 27, 2020 5:24 PM - Last modified Apr. 27, 2020 5:25 PM