Presentation is loading. Please wait.

Presentation is loading. Please wait.

MiniDraw Testing COMP 102 # T1

Similar presentations

Presentation on theme: "MiniDraw Testing COMP 102 # T1"— Presentation transcript:

1 MiniDraw Testing COMP 102 #28 2012T1
Got to slide 10.

2 Outline Designing MiniDraw Announcements: Lab 10 available

3 Designing MiniDraw (Assig 10)
A simple drawing editor Allows user to create drawings consisting of shapes: rectangles, ovals, lines, dots, trees, different colours. can add a new shape, delete a shape move a shape to a different position resize a shape save the current drawing to a file load a previous drawing from a file and edit it further.

4 Demo

5 Designing MiniDraw What Types of Data?
Program must remember all the shapes so it can edit them ⇒ Rectangles, Lines, Ovals, Dots, Trees ⇒ List of the shapes MiniDraw (The user interface) (Contains an arrayof shapes) Rectangle Line Oval Dot Tree

6 Designing MiniDraw What Methods? MiniDraw Interaction fields Array of
shapes Same methods, but not the same effects. (eg, will draw themselves differently) Need different fields to store different information Rectangle redraw moveBy : Line redraw moveBy : Oval redraw moveBy : Dot redraw moveBy : Tree redraw moveBy :

7 Array of shapes Can't be an array of Line
Can't be an array of Object (well…, yucky if we do) Need an interface class for the Shape type public Interface Shape{ public void redraw(); public void moveBy(double dx, double dy); public boolean on(double x, double y); public boolean resize(double dx, double dy); public String toString(); : } Can use Shape as a type. Lines, Rectangles, etc must be Shapes also

8 Implementing the Shape Interface
If you define classes that implement the interface: public class Rectangle implements Shape{ private int x; …… public class Line implements Shape{ These classes must define all the specified methods (including the right parameters)

9 MiniDraw class diagram
With the Shape Interface: MiniDraw User Interface Array of Shape Shape Rectangle render moveBy … Line render moveBy … Oval render moveBy … Dot render moveBy … Tree render moveBy …

10 MiniDraw in operation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x: y: x2 y2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x: y: x2 y2: col: x: y: wd: ht: col: x: y: wd: ht: col:

11 Testing and Debugging Test methods: "Unit Testing" Tracing the code.
Method that will create an object of one class and run through all the methods to test them out. TestRect, TestOval, TestDot, are written for you. Tracing the code. print statements to show a log of the state of the program. Typically done with System.out.println(……) But then have to comment them out….. The Trace object in the comp102 library makes this easy Trace is a separate window that you can print to Can be turned on and off from the menu. has a number of Trace.println statements

12 Trace in MiniDraw public void addShape(double x1, double y1, double x2, double y2){ Trace.printf("Drawing shape %s, at (%.2f, %.2f)-(%.2f, %.2f)\n", this.currentAction, x1, y1, x2, y2); : public void deleteShape(double x, double y){ Trace.printf("Deleting shape under (%.2f, %.2f)\n", x, y); A Trace.print at the beginning of a method provides a log of the method calls. You can add additional Trace.print statements inside tricky code.

Download ppt "MiniDraw Testing COMP 102 # T1"

Similar presentations

Ads by Google