Circle
class — the same one we've been using in class and in lab.
Circle
should behave exactly as described, and the method names and printed output should match the assignment description. As part of the grading process I will run a program that creates instances of your class and tests them. If your names or other details differ, my testing code won't compile and I'll get sad and grumpy.
package.bluej
file within the project to open it in BlueJ. When it opens, you'll see that only the Canvas
and Circle
classes are included. All of your changes will be to the Circle
class.
moveDiagonally
, that takes a single input from the user — the distance to move — and moves that far both horizontally and vertically. I've written the outline of the method, but you need to add some code where it says to in order to make the circle move as it should. Think about which methods you'd call on a Circle
object to make it do those two move operations. Then think about what the equivalent lines of code would be to perform those operations, and add them at line 35. Compile and test your method before moving on. (Note: Moving the same distance horizontally and vertically means it will only be able to move up and to the left, or down and to the right, but that's ok.)
Circle
has been asked to move, and to report that information when the user requests it. We'll break this down into smaller steps so it's easier to manage:
diameter
, xPosition
, etc, are located. Use a meaningful name for the field so your code's easier to read, and make sure it's of the appropriate type.
moveDiagonally
operation you just implemented should only count as one move since the user can't distinguish the horizontal and vertical moves being performed — it just looks like a single movement. Verify that your code works by creating a circle, moving it, and using the object inspector (double clicking the red Circle object) to verify that the new field's value is updating properly.
printNumberOfMoves
below moveDiagonally
. It should print a line of output that looks exactly like the one below (assuming it has moved five times). The output will appear in the Terminal window when the method is called.
Circle has moved 5 times
You'll need to write the entire method yourself this time, since the project doesn't contain a starting point for it like it did for moveDiagonally
. Test your code before proceeding.
moveDiagonally
method works properly and has correct name.
printNumberOfMoves
method has the correct name.
printNumberOfMoves
is properly formatted.
resetCount
that sets the number of moves back to zero whenever it's called. Test it to make sure it works the way you expect it to.