        |
AM:Q&A for Homework 2
Post your questions on Homework #2:
Thursday, 13 March 2008, 6:50:36 pm, cecs174
My question is about the fancyBorder method. I was wondering what you meant by instructing us to set it up with at least one parameter. I'm not sure what you mean by this...do you want us to ask for a certain variable within the method ... do you want to set it up with different colors...or is the parameter your asking for something completely different from what I'm thinking about.
| Answer: A parameter for a method is used to make the method more flexible and general when it's invoked. We first learned about parameters when designing a drawSquare() method for the Turtle class. We learned that by defining the method as: public void drawSquare(int length), we can use it to have a turtle object draw squares of any length. We specify the actual parameter when calling the method, thus: pete.drawSquare(75); will draw a 75x75 square whereas pete.drawSquare(140); will draw a 140x140 square, etc. We defined the method once with a parameter, and now any length square can be drawn. Thus, with the drawFancy() method, you should define the method with a parameter such that the border will be drawn accordingly. The type of parameter and what it is used for is completely up to you. If for example, your method is defined as public void fancyBorder(int someVariableName), then you can program the method to use the integer that will be provided when it is called, so a call like so pictureObject.fancyBorder(3); should give a different result than pictureObject.fancyBorder(5);. Again, what your method does with the actual parameter passed in, is up to you. Note, that I'm using an integer parameter as an example, again, it is up to you to determine the type of the parameter and what to do with it. |
Monday, 17 March 2008, 4:20:38 pm, cecs174
[Dr. Monge's paraphrase of questions about embedImage()]: Can you explain what an argument is? The assignment describes that embedImage() takes four arguments. What are they for?
Answer: By arguments, I meant the actual parameters (or parameter values) that you send to the embedImage() method when calling it. These are the formal parameters when defining the method in the Picture class. Thus the method definition starts as follows: public void embedImage(Picture sourcePicture, int sourceX, int sourceY, int squareLength) A call to this method looks like so (assuming that butterfly and csulbTower are defined as Picture objects): butterfly.embedImage(csulbTower, 170, 59, 200); That's the method call that I used to generate the example described in the assignment description and which generates this picture:  |
Monday, 17 March 2008, 4:42 pm, cecs174
Where should the embedded image be placed? Can we place it exactly at the lower-right corner?
| Answer: You can decide how much space to leave between the edges of the lower-right corner, so long as there is some space and of course there needs to be enough space for the inset picture to fit. |
Tuesday, 18 March 2008, 1:35:40 pm, cecs174
I'm having trouble making color a parameter for the drawFancyBorder method...
I think it should go something like this:
public void drawFancyBorder(java.awt.Color.COLOR)
Answer: Close... the type of the parameter is java.awt.Color and then you must have a name for the parameter. Putting it all together, it is now: public void drawFancyBorder(java.awt.Color borderColor) Of course, since there is an import of the java.awt package already included in the Picture.java file, then you should be able to just do this: public void drawFancyBorder(Color borderColor) |
Thursday, 20 March 2008, 2:25:28 pm, cecs174
Can you give us a hint on the drawBorder for the embedImage()?
Please!
| Answer: Of course! You are required to draw a border around the inside of a picture. The code you use to implement that method can be used to draw a border around the embedded image. You cannot call the drawBorder() method. Since you don't want to draw a border around the entire picture, but only around the square section that you've just embedded. Now, if you inspect your code for drawBorder() you'll find that your border is a rectangle whose top-left corner is located at (0,0), the width and height of the rectangle is the width and height of your picture. You need to do something similar here, but this time you want a square whose top-left corner is located at (targetX, targetY) and the width and height are the size of the square. We discussed what the values of targetX and targetY should be in Wednesday's class. I hope this helps. Let me know if you need more information or come by to see me for more help, I'll be around on Friday. |
Friday, 21 March 2008, 11:46:54 am, cecs174
> target.explore();
NoClassDefFoundError: PictureExplorer$PictureExplorerFocusTraversalPolicy
at SimplePicture.explore(SimplePicture.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
why is it showing me this?
| Answer: Assuming that target is a Picture object that you've created, there should not be problems with calling the explore() method on it. I've not had this error before. Try restarting DrJava. These questions are difficult to answer without having the code that generated the runtime error, if you still have this problem, please send me the code via e-mail along with the steps that generated the error. |
Friday, 21 March 2008, 3:21:16 pm, cecs174
why isnt my program using the picture class meathods every time i compile its good but when i rum my program it gives this error on the interactions pane
NoSuchMethodError: Picture.drawBorder()V
at PicCollage.main(PicCollage.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
>
| Answer: This is also another problem that it's difficult to help you with unless I can see the code that generated. Do not post code here. Send it via e-mail to me so that I can help you with it. |
Link to this Page
|