finalv11_soln

finalv11_soln - 1.00 Introduction to Computers and...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1.00 Spring 2003 Final Exam 1/17 5/12/2005 1.00 Introduction to Computers and Engineering Problem Solving Final Exam May 21, 2003 Question Points Question 1 / 5 Question 2 / 10 Question 3 / 20 Question 4 / 10 Question 5 / 10 Question 6 / 25 Question 7 / 20 Total / 100 Name: Email Address: TA: Section: You have three hours to complete this exam. For coding questions, you do not need to include comments, and you should assume that all necessary files have already been imported. Final exam is open book, open notes. No laptops, calculators, cell phones or other electronics are allowed. Sharing of notes or books is not allowed.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1.00 Spring 2003 Final Exam 2/17 5/12/2005 Problem 1. Exceptions (5 points) Which of the following statements is true given the program ExceptionTest? (Circle only one answer.) a. The program will not compile. b. The program will compile. If we run it, it will throw an exception before outputting any results. c. The program will compile. If we run it, it will output some results, but then throw an exception. d. The program will compile and run without throwing any exceptions. public class ExceptionTest { public static void main(String args[]) { String[] greek = {"Alpha", "Beta", "Gamma"}; System.out.println(greek[1]); System.out.println(greek[3]); } }
Background image of page 2
1.00 Spring 2003 Final Exam 3/17 5/12/2005 Problem 2. Abstract Classes & Inheritance (10 points) Enraged by the high price of software, you decide to martyr yourself by writing a free Java version of Photoshop for the world, which you call “jimp”. You’d like for the user to be able to scale, and rotate shapes such as rectangles, triangles, circles, and squares. You decide to create an abstract Shape class to represent the commonalities these shapes will share in your program. // Shape.java 1 public abstract class Shape 2 { 3 // x,y coordinates of upper left corner of Shape's bounding box 4 private int xCoord; 5 private int yCoord; 6 private final String type; // rectangle, circle, triangle, etc 7 8 public Shape(int x, int y, String t) 9 { 10 xCoord=x; 11 yCoord=y; 12 type=t; 13 } 14 15 // get methods omitted 16 public abstract void scale(double factor); 17 public final void move(int newX, int newY) 18 { 19 xCoord=newX; 20 yCoord=newY; 21 } 22 23 public String toString(){ 24 return "SHAPE:"+type+",("+xCoord+","+yCoord+")"; 25 } 26 } You then define a Rotatable interface and a Rectangle class as follows. The Rectangle class contains a main() method for unit testing. 1 // Rotatable.java 2 public interface Rotatable{ 3 public void rotate(double theta); 4 } 1 // Rectangle.java 2 public class Rectangle extends Shape implements Rotatable 3 { 4 private int width; 5 private int height; 6
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1.00 Spring 2003 Final Exam 4/17 5/12/2005 7 // The type of a Rectangle is "rectangle". 8
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

finalv11_soln - 1.00 Introduction to Computers and...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online