CS1026a: Assignment 1 solution

Task: In this assignment, you will write a complete program in Java that uses the Turtle class to draw shapes on the screen. Your task is to use combinations of squares, rectangles and octagons to draw a robot (just the head is ok, or something else of your choosing) on the screen. You can make it look however you like as long as it meets the following specifications. Be creative!
Functional Specifications: 1. It is assumed that you have added the method drawSquare with the header public void drawSquare(int width) to your Turtle.java already. It must be as described in the Lecture Notes: your turtle must start at the top left hand corner, facing north, and finish in the same place, facing north. 2. You will add two new methods to the Turtle class in your file Turtle.java: • A method drawRectangle with the header: public void drawRectangle(int width, int height) that draws a rectangle on the screen with the width and height passed in as integer parameters. Your turtle must start at the top left hand corner, facing north, and finish in the same place, facing north
• A method drawOctagon(int length) with the header: public void drawOctagon(int length) that draws an octagon on the screen, with the length of each side passed in as the integer parameter. An octagon has all eight external angles of 45 degrees. Your turtle must start at the vertex marked in the diagram, facing north, and finish at the same point, facing north. An octagon looks like this: 3. Write a complete Java program that makes use of your methods drawSquare, drawRectangle and drawOctagon to draw a robot (or just its head, or a figure of your choosing) on the screen. 45 Turtle starts here
4. Your Java program will be in a class called TurtleArt as shown below. Using the definitions pane of DrJava, you will add Java statements that actually draw the required options. The program will be stored in a file called TurtleArt.java. import java.awt.Color; public class TurtleArt { public static void main (String[] args) { /* Insert your code here */ } } 5. The figure will be in its own world, and you may use as many turtles as you like to draw it. 6. You must use: • At least 2 rectangles of different sizes • At least 2 squares of different sizes • At least 2 octagons of different sizes • At least two colors other than black • At least two pen widths 7. You may use any of the methods of the Turtle class that are already defined. You may draw lines as well as the shapes. You may write other methods to help you if you like. 8. You can be as creative as you want, although there are no marks for “degree of difficulty”. ***Important! You must follow all the specifications above for your program***
Non-functional Specifications: 1. Include brief comments in your code that explain what each method is doing. 2. Assignments are to be done individually and must be your own work. Software will be used to detect cheating. 3. Use Java conventions and good Java programming techniques, for example: i. Meaningful variable names ii. Conventions for naming variables and constants iii. Use of constants where appropriate iv. Readability: indentation, white space, consistency
What You Will Be Marked On: 1. Functional specifications: ü Are the required methods written according to specifications? ü Do they work as specified? Pay attention to details! ü Are they called as specified? ü Are the objects drawn according to the specifications? 2. Non-functional specifications: as described above 3. Assignment submission: via the OWL, though the assignment submission in OWL.