Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Similar documents
Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Final Exam CS 251, Intermediate Programming December 13, 2017

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

ITI Introduction to Computing II

SampleApp.java. Page 1

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

ITI Introduction to Computing II

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

Java Interfaces Part 1 - Events Version 1.1

CSE 214 Computer Science II Java Classes and Information Hiding

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Graphical User Interface

Object-Oriented Software Engineering Re-exam, 2012 (Also Object-Oriented Analysis, Design and Programming, Re-exam, 2012)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

8. Polymorphism and Inheritance

Final Exam CS 251, Intermediate Programming December 10, 2014

COMP16121 Sample Code Lecture 1

JFrame In Swing, a JFrame is similar to a window in your operating system

Give one example where you might wish to use a three dimensional array

For example, here is a code snippet that supplies a legal data set to the constructor:

This exam is open book. Each question is worth 3 points.

Chapter 6 Introduction to Defining Classes

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Java Never Ends MULTITHREADING 958 Example: A Nonresponsive GUI 959

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

First Name: AITI 2004: Exam 2 July 19, 2004

Object-Oriented Software Engineering (Re-exam for Object-Oriented Analysis, Design and Programming)

CSCI 201L Midterm Written Summer % of course grade

Object- Oriented Analysis, Design and Programming

CSEN 202: Introduction to Computer Programming

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

CSE 331 Final Exam 6/7/16

About This Lecture. Data Abstraction - Interfaces and Implementations. Outline. Object Concepts. Object Class, Protocol and State.

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Language Features. 1. The primitive types int, double, and boolean are part of the AP

C12a: The Object Superclass and Selected Methods

Selected Questions from by Nageshwara Rao

Final Examination Semester 3 / Year 2010

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Java Never Ends CHAPTER MULTITHREADING 1100 Example: A Nonresponsive GUI 1101

COP 3330 Final Exam Review

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Based on slides by Prof. Burton Ma

CSCI 212 Practice Final Exam Summer Instructor: Krishna Mahavadi

CS1004: Intro to CS in Java, Spring 2005

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

Computer Science 145

CS/ENGRD 2110 FALL2017. Lecture 4: The class hierarchy; static components

CS 101 Fall 2006 Midterm 3 Name: ID:

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.

CSE 131 Introduction to Computer Science Fall Final Exam

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t;

Inheritance Systems. Merchandise. Television Camcorder Shirt Shoe Dress 9.1.1

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Operations. I Forgot 9/4/2016 COMPUTER SCIENCE DEPARTMENT PICNIC. If you forgot your IClicker, or your batteries fail during the exam

Inheritance (Extends) Overriding methods IS-A Vs. HAS-A Polymorphism. superclass. is-a. subclass

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

Lecture 4: The class hierarchy; static components

Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet.

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Classes. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java.

Chapter 12: Inheritance

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

Object Oriented Programming 2015/16. Final Exam June 28, 2016

Programming Languages and Techniques (CIS120)

CS 180 Final Exam Review 12/(11, 12)/08

CS 520 Theory and Practice of Software Engineering Fall 2018

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

Example: Count of Points

Multimedia Programming

Introduction to Computer Science II (CSI 1101) Midterm Examination

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

CS 520 Theory and Practice of Software Engineering Fall 2017

Midterm assessment - MAKEUP Fall 2010

Transcription:

Page 1 of 16 HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2005 FINAL EXAMINATION 9am to 12noon, 19 DECEMBER 2005 Instructor: Alan McLeod If the instructor is unavailable in the examination room and if doubt exists as to the interpretation of any problem, the candidate is urged to submit with the answer paper a clear statement of any assumptions made. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. Please write your answers in the boxes provided. Extra space is available on page 16 of the exam. The back of any page can be used for rough work. This exam refers exclusively to the use of the Java language. Comments are not required in the code you write. This is a closed book exam. No computers or calculators are allowed. Student Number: Problem 1: / Problem 2: / Problem 3: / TOTAL: /

Student Number: Page 2 of 16 Problem 1) [ marks] Three classes form an object hierarchy. Here are two of the three classes, ClassR and ClassA: public abstract class ClassR { final int ONE = 1; abstract int method1 (int a, int b); public int method2 (int a) { return a + a; } // end method2 } // end ClassR public class ClassA extends ClassM { public ClassA (int a, int b) { super(a, b); } // end ClassA constructor public int method3 (int a) { return ONE + super.method3(a); } // end method3 public int method4 () { return getx() + gety(); } // end method4 } // end ClassA On the next page is a separate testing class with a copy of its console output, which illustrates the operation of the methods in the hierarchy:

Student Number: Page 3 of 16 public class MainClass { public static void main(string[] args) { ClassA ca = new ClassA(100, 1000); System.out.println(ca.method1(10, 20)); System.out.println(ca.method2(30)); System.out.println(ca.method3(40)); System.out.println(ca.method4()); } // end main } // end MainClass /* OUTPUT: 30 60 1141 1100 */ On the next page, write the complete code for the missing class. Write only the code required to complete the hierarchy in the most efficient way. Note that the only arithmetic operation used in any of the methods is addition.

Student Number: Page 4 of 16

Student Number: Page 5 of 16 Problem 2) [ marks] For this problem you will need to write a complete class called SurfaceShape, with all the methods that should be present when you follow good encapsulation practices. You will need to use some other classes that are provided below. You will also be given a syntax summary for the ArrayList<T> class. SurfaceShape is designed to hold a collection of points in space that all lie on a plane. Use an ArrayList<T> for the collection. The constructor of the class will need to calculate the equation of the plane for the points, and it will also store this equation as an object. Here is an exception class to be used by SurfaceShape: public class SurfaceShapeException extends Exception { public SurfaceShapeException (String s) { super(s); } public SurfaceShapeException () { super("illegal surface shape!"); } } // end SurfaceShapeException class Points will be stored as objects, as defined by the Point class: public class Point { private double x, y, z; public Point (double x, double y, double z) { this.x = x; this.y = y; this.z = z; } // end Point constructor public double getx () { return x; } public double gety () { return y; } public double getz () { return z; } public boolean equals (Object p) { boolean check = false; Point pp; double tolerance = 1e-6; if (p instanceof Point) {

Student Number: Page 6 of 16 pp = (Point)p; check = Math.abs(pp.x - x) < tolerance; check = check && Math.abs(pp.y - y) < tolerance; check = check && Math.abs(pp.z - z) < tolerance; } // end if return check; } // end equals public Object clone () { return new Point (x, y, z); } // end close } // end Point class The equation of the surface will be stored in a SurfaceEquation object: public class SurfaceEquation { double a, b, c; public SurfaceEquation (double a, double b, double c) { this.a = a; this.b = b; this.c = c; } // end SurfaceEquation constructor public double calcz (double x, double y) { return a * x + b * y + c; } // end calcz public String tostring () { return String.format("z = %6.3f * x + %6.3f * y + %6.3f", a, b, c); } // end tostring public Object clone () { return new SurfaceEquation(a, b, c); } // end clone } // end SurfaceEquation

Student Number: Page 7 of 16 Assume the existence of a class called MatrixSolver that contains a static method called gaussjordan that provides the solution to a system of simultaneous equations. Remember assignment 2? The system of equations is described by: A x = b where A, x and b are matrices. A is n by n, and x and b are of size n. The gaussjordan method accepts the matrices A and b as arrays of double s, and returns the matrix r as an array of double s, where r is defined as: I x = r The matrix I is the identity matrix. Consider describing a plane, in three dimensions (x, y and z) using the general equation: z = ax + by + c If you had three points: (x 1, y 1, z 1 ), (x 2, y 2, z 2 ) and (x 3, y 3, z 3 ), then you could create the following system of equations: Or, in matrix form: ax 1 + by 1 + c = z 1 ax 2 + by 2 + c = z 2 ax 3 + by 3 + c = z 3 x x x 1 2 3 y y y 1 2 3 1.0 a z 1.0 = b z 1.0 c z 1 2 2 A solution to this matrix equation would yield the equation coefficients, a, b and c. The SurfaceShape class constructor accepts an ArrayList<T> which has been typed to contain Point objects. The constructor will throw an exception if the ArrayList is either null or contains fewer than three Point s. Next, the constructor will have to determine the equation of the plane using the first three Point s in the ArrayList. After creating a SurfaceEquation object, you will throw an exception if any of the remaining Point s in the ArrayList do not lie on the plane. For a Point to be said to lie on the plane, calculated and given z values must agree to less than 1x10-6.

Student Number: Page 8 of 16 You will find the following ArrayList<T> methods useful: size() // returns the number of occupied positions in the // ArrayList collection add(object) // adds the provided object to the end of the ArrayList // collection get(int) // returns the object at the given position in the // ArrayList collection as an Object contains(object) // Returns true if the collection contains the Object // provided as a parameter Do not write any mutator methods for your SurfaceShape class. You will need to write the two accessors, one for the ArrayList and the other for the SurfaceEquation object. Your equals method should override the equals method inherited from Object. Equality is defined as both ArrayList attributes having the same size and containing all the same Point s in any order. Compare SurfaceShape objects based only on the size of their ArrayList collections. Return a positive integer if the supplied object has more Point s. Your tostring() method should return a String containing just the number of Point s and the equation describing the plane. For example, it could return: 10 points, on plane: z = 4.000 * x + 5.000 * y + 7.000 Finally, include a clone() method that returns an Object. No other methods are required. That was a very long description! You solution should be shorter. Write your class in the space provided on the next three pages.

Student Number: Page 9 of 16

Student Number: Page 10 of 16

Student Number: Page 11 of 16

Student Number: Page 12 of 16 Problem 3) [ marks] For this problem you will complete the code in the following GUI window definition. When your window first opens, it looks like: When you click on the Make a Wish button, you will see: The window is displayed by the code on the next page:

Student Number: Page 13 of 16 public class GUIExamProblem { public static void main(string[] args) { int nummessages = 40; GUIExamProblemWindow gep = new GUIExamProblemWindow(numMessages); gep.setvisible(true); } // end main } // end GUIExamProblem You will find the following methods useful: sethorizontalalignment(jlabel.center) add(component) add(component, BorderLayout.position) addactionlistener(class_implementing_actionlistener) settext(string) Inside your ActionListener class, you will need to define the following method: public void actionperformed (ActionEvent e) Here is the start of the GUIExamProblemWindow class definition: import javax.swing.jframe; import javax.swing.jbutton; import javax.swing.jpanel; import javax.swing.jlabel; import java.awt.flowlayout; import java.awt.borderlayout; import java.awt.gridlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; public class GUIExamProblemWindow extends JFrame { private final int WIDTH = 440; private final int HEIGHT = 300;

Student Number: Page 14 of 16 // Add more class attributes here, if necessary int nummessages; public GUIExamProblemWindow (int nummessages) { super(); this.nummessages = nummessages; setdefaultcloseoperation(jframe.exit_on_close); settitle("gui Layout Problem"); setsize(width, HEIGHT); // Complete the class below and on the next page:

Student Number: Page 15 of 16

Student Number: Page 16 of 16 (Extra page)