Presentation is loading. Please wait.

Presentation is loading. Please wait.

Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington MiniDraw Testing COMP 102.

Similar presentations


Presentation on theme: "Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington MiniDraw Testing COMP 102."— Presentation transcript:

1 Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington MiniDraw Testing COMP 102 # T1

2 © Peter Andreae COMP :2 Outline Designing MiniDraw Announcements: Lab 10 available

3 © Peter Andreae COMP :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 © Peter Andreae COMP :4 Demo

5 © Peter Andreae COMP :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 (The user interface) (Contains an arrayof shapes) MiniDraw LineOvalDotTreeRectangle

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

7 © Peter Andreae COMP :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 © Peter Andreae COMP :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{ private int x; …… These classes must define all the specified methods (including the right parameters)

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

10 © Peter Andreae COMP :10 MiniDraw in operation x: y: wd: ht: col: x: y: wd: ht: col: x: y: x2 y2: col:

11 © Peter Andreae COMP :11 Testing and Debugging Test methods: "Unit Testing" 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. MiniDraw.java has a number of Trace.println statements

12 © Peter Andreae COMP :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 "Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington MiniDraw Testing COMP 102."

Similar presentations


Ads by Google