DOC PREVIEW
UMD CMSC 433 - Final Exam

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Final ExamCMSC 433Programming Language Technologies and ParadigmsFall 2008December 18, 2008GuidelinesPut your name on each page before starting the exam. Write your answers directly on the exam sheets,using the back of the page as necessary. If you finish with more than 15 minutes left in the class, thenbring your exam to the front when you are finished and leave the class as quietly as possible. Otherwise,please stay in your seat until the end.If you have a question, raise your hand and the proctor will come to you. Note, that he will notanswer general questions. If you feel an exam question assumes something that is not written, write itdown on your exam sheet. Barring some unforeseen and egregious error, however, you shouldn’t needto do this at all, so be careful when making assumptions.NOTE: There are quite a few questions to answer. Get started right away. Read each questioncarefully and answer the question that has been asked. Budget your time wisely. If you can’t answer aquestion in a few minutes, move on and come back to the difficult question later. Do not get boggeddown on a single question.Question Points Score1 102 153 154 105 106 157 108 15Total 1001. Design Principles: Short answers (10 points). Give very short (1 to 2 sentences for each issue)answers to the following questions. Longer responses to these questions will not be read.(a) In the context of software design, what is abstraction? Answer:decompose system into abstract componen ts. Abstractions emphasize essential char-acteristics and suppress implementation details(b) In the context of software design, what is hierarchy? Answer:restrict module interactions by restricting topology of module relationships(c) In the context of software design, what is information hiding? Answer:Defining modules such that each module encapsulates something that is likely tochange.22. The Decorator Pattern (15 points). You are developing a graph plotting application that usesthe Decorator pattern. Your application has three decorator classes: BasePoint, SnapToGrid, andPrintPoint. Each of these classes implements the Point interface. The Point interface defines threemethods: getX() - which returns the Point’s X coordinate; getY() - which returns the Point’s Ycoordinate; and move (int dx, int dy) - which moves the point dx units on the X axis and dy unitson the Y axis.interface Point {public void move (int dx, int dy);public int getX ();public int getY();}Assume the graphing plane has an origin of (0,0) and that the plane encompasses all non-negativeXY coordinates. Also assume only valid move operations which leave the point within the plane.That is, don’t worry about error handling for illegal move() operations.BasePoint represents a point in a 2D plane. BasePoint cannot decorate other Points. The Base-Point constructor takes an initial XY coordinate for the Point.SnapToGrid can decorate other Points. The SnapToGrid constructor takes two arguments: thegridSize and a Point to decorate. SnapToGrid restricts Points to lie on XY coordinates that areinteger multiples of the gridSize (gridlines). So if you try to create or move a SnapToGrid pointwith/to coordinate (22,25) and the gridSize is 10, then the Point should be placed at (20,30). Thisis because the nearest X coordinate to 22 that is on the grid is 20 and the nearest Y coordinate to25 that is on the grid is 30 (round up for Points that are equidistant to two grid lines).PrintPoint logs the effect of each operation to standardout.The PointClient Driver and BasePoint classes are as follows:public class PointClient {public static void main (String [] args) {Point a = new BasePoint (33,17); // New Point created at (33,17)Point b = new SnapToGrid(10,a); // Point moved to nearest gridline (30,20)Point c = new PrintPoint(b); // Adds logging capabilityc.move(-16,5); // Point moves to (10,20). Prints: "Moved to (10,30)"c.getX(); // Prints: "getX() returns: 10"c.getY(); // Prints: "getY() returns: 30"}}public class BasePoint implements Point {int x, y;BasePoint (int x, int y) {this.x = x; this.y = y;}public void move (int dx, int dy) {this.x += dx; this.y += dy;}public int getX () {return x;}public int getY() {return y;}}3Fill in the code needed to implement the PrintPoint and SnapToGrid classes below:public class PrintPoint implements Point {Point p;PrintPoint (Point p) {}public int getX() {}public int getY() {}public void move(int dx, int dy) {}}4public class SnapToGrid implements Point {int gridSize;Point p;SnapToGrid(int gridSize, Point p) {}public void move(int dx, int dy) {}public int getX() {}public int getY() {}}5Answer:public class PrintPoint implements Point {Point p;PrintPoint (Point p) {this.p = p;}public int getX() {int x = p.getX();System.out.println(‘‘getX() returns: ‘‘ + x);return x;}public int getY() {int y = p.getY();System.out.println(‘‘getY() returns: ‘‘ + y);return y;}public void move(int dx, int dy) {p.move(dx, dy);System.out.println(‘‘Moved to (‘‘ + p.getX() + ‘‘,’’ + p.getY() + ‘‘)’’);}}public class SnapToGrid implements Point {int gridSize;Point p;SnapToGrid(int gridSize, Point p) {this.gridSize = gridSize;this.p = p;move(0, 0);}public void move(int dx, int dy) {int tmpX = getX() + dx, tmpY = dy + getY();int newX = (tmpX % gridSize);if (newX >= gridSize / 2) {tmpX += gridSize - newX;} else {tmpX -= newX;}int newY = (tmpY % gridSize);if (newY >= gridSize / 2) {tmpY += gridSize - newY;} else {tmpY -= newY;}p.move(tmpX - getX(), tmpY - getY());}public int getX() { return p.getX(); }public int getY() { return p.getY(); }}63. Test Coverage (15 points). Consider the code below. In class we discussed three different kinds ofcoverage criteria: statement, branch and condition. Give a set of test cases (each test case is a listof values for a, b and c) that achieves: (a) 100% statement coverage, but less than 100% branchand condition coverage, (b) 100% branch coverage but less than 100% condition coverage, and (c)100% condition coverage.class CoverageTest {static public void main(String[] args) {boolean a = Boolean.parseBoolean(args[0]);boolean done = Boolean.parseBoolean(args[1]);int c = Integer.parseInt(args[2]);if (a && (c < 0 || done)) {c = 100;} else {done = !done;}while (c <= 0 || !done) {c--;if (c == 23) {done = true;}}}}Answer:a) statement coverageT F -1 \\F F -1 \\b) branch coverageT F -1 \\F F -1 \\c) condition coverageT F -1 \\F T 0 \\F T -1 \\74. State Dependent Actions (10 Points). The following code models a


View Full Document

UMD CMSC 433 - Final Exam

Documents in this Course
Trace 1

Trace 1

62 pages

Reflection

Reflection

137 pages

Testing

Testing

25 pages

Paradigms

Paradigms

10 pages

Testing

Testing

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Trace 1

Trace 1

46 pages

Jini

Jini

4 pages

Final

Final

15 pages

Java RMI

Java RMI

13 pages

Testing

Testing

16 pages

Load more
Download Final Exam
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Final Exam and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Final Exam 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?