| ||||||||||
Question: DO WE NEED T SQUARE TO TURN IN THIS HOMEWORK |
Question: How do we test our methods in the interactions pane after we have compiled Picture.java with no errors to see if the expected manipulation happens? |
Picture p = new Picture(FileChooser.getMediaPath("swan.jpg")); p.show() // Now original picture is displayed p.insertNewMethodNameHere(); // Replace with the name of your method p.show(); // If the image didn't change, try resizing it to update itSomething along those lines should work. If your method doesn't return void you may have to adjust it accordingly. Ricardo Corrales.
//declaration of the picture (if it says something like cannot load nullswan.jpg, set your media path with FileChooser.setMediaPath("yourmediapath");) Picture p = new Picture(FileChooser.getMediaPath("swan.jpg")); //show the original picture p.show(); //call the method on the original picture and assign it to another variable Picture modP = p.yourNonVoidMethod(); //show the modified picture modp modP.show();Dawn Finney
Question: A continuation from the question posted above, i did the void code and the picture did what i expected but when i entered the third line in the interactions pane which is the p.methodname();, I got a long error. the error read ArrayIndexOutOfBoundsException. Should i worry since the picture was still modified, and what could be causing the error? |
//declares arr as an int array of length 4 int[] arr = new int[4];Now try these lines:
arr[-1] arr[4]You should get the same error. This occurs because the indices of arr are 0 - 3 and when you try to access a index outside of that range you get an error. I would suggest looking at your loop especially the ending parameter, because many people forget that java is 0-indexed (meaning that the indices start from 0). If you are calculating your index in some way, I would look that as well. Dawn Finney