Classwork 2: January 14, 2008
Group Writeup (10 pts)
For group work, please turn in one sheet of paper with all the names of those who participated in your group.
For this part, assume an Artist class exists that provides the following methods for drawing lines and moving the pen.
This method draws a vertical line of the given length, starting from the current position and going down. The current position is NOT changed. (after drawing, the pen point goes back to where it was before it drew the line).
This method draws a horizontal line of the given length, starting from the current position and going right. The current position is NOT changed.
This method moves the current position distance units to the right.
This method moves the current position distance units to the left.
This method moves the current position distance units up.
This method moves the current position distance units down.
Artist picasso = new Artist(); picasso.drawLineDown(7); picasso.moveDown(3); picasso.drawLineRight(2); picasso.moveUp(3); picasso.moveRight(2); picasso.drawLineDown(7); picasso.moveRight(2); picasso.drawLineRight(2); picasso.moveRight(1); picasso.drawLineDown(7); picasso.moveLeft(1); picasso.moveDown(7); picasso.drawLineRight(2); | |
Write Java code for a method called drawSpiral(int size)
that given size, draws a size-spiral. First think about how to give
code for a 1-spiral, 2-spiral, 3-spiral and 4-spiral.
This exercise helps in understanding what happens when objects are declared and created, and when methods are called. It also focuses on the difference between copying a primitive type and copying an object.
Consider the following Java code that compiles and runs.
Look at the Car class and the DriveCars class and discuss them with your group. For the Car class, find the data members for the class. Find all the methods for the class.
Write answers to the following questions.