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

Similar documents
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.

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.

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.

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

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.

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

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

COMP16121 Sample Code Lecture 1

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

Example: Building a Java GUI

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

Example: Building a Java GUI

SampleApp.java. Page 1

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

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

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects

1.00/ Introduction to Computers and Engineering Problem Solving. Quiz 2 / November 5, 2004

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

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

We are on the GUI fast track path

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

CMP 326 Midterm Fall 2015

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

CSCI 201L Midterm Written Summer % of course grade

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

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

CSIS 10A Assignment 7 SOLUTIONS

8. Polymorphism and Inheritance

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

Final Exam CS 251, Intermediate Programming December 13, 2017

Agenda. Container and Component

RAIK 183H Examination 2 Solution. November 10, 2014

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

CS Exam 3 - Spring 2010

Chapter 13 Lab Advanced GUI Applications

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

Final Examination Semester 2 / Year 2010

CS Exam 3 - Spring 2010

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

Java Never Ends MULTITHREADING 958 Example: A Nonresponsive GUI 959

Midterm assessment - MAKEUP Fall 2010

CSCI 201L Midterm Written SOLUTION Summer % of course grade

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

Swing I CHAPTER EVENT-DRIVEN PROGRAMMING 921 Events and Listeners 921

Swing I Event-Driven Programming Buttons, Events, and Other Swing Basics Containers and Layout Managers 946

Window Interfaces Using Swing. Chapter 12

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

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

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 :) )

Graphical User Interfaces in Java - SWING

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

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

More about GUIs GEEN163

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

User interfaces and Swing

b. Suppose you enter input from the console, when you run the program. What is the output?

Final Exam CS 251, Intermediate Programming December 10, 2014

CMP-326 Exam 2 Spring 2018 Solutions Question 1. Version 1. Version 2

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Chapter 8 Objects and Classes Part 1

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

APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

RAIK 183H Examination 2 Solution. November 11, 2013

The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324

Dr. Hikmat A. M. AbdelJaber

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

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

CMP-326 Exam 2 Spring 2018 Total 120 Points Version 1

encompass a group of features for building Graphical User Interfaces (GUI).

Ryerson University Department of Electrical & Computer Engineering COE618 Midterm Examination February 26, 2013

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

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

Final Examination Semester 2 / Year 2011

CS 113 PRACTICE FINAL

To gain experience using GUI components and listeners.

!"# $ %&# %####' #&() % # # # #&* # ## +, # -

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

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

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

DAFTAR LAMPIRAN. Source Code Java Aplikasi Keyword to Image Renamer Split

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

Transcription:

SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor 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 17 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. For full marks, code must be efficient as well as correct. This is a closed book exam. No computers or calculators are allowed. Student Number: Problem 1: / 8 Problem 4: / 18 Problem 2: / 10 Problem 5: / 10 Problem 3: / 14 TOTAL: / 60

Student Number: Page 2 of 17 Problem 1) [4 marks for a) and 4 marks for b)] a) Provide the output of each of the following println statements, in the box beside each statement. Remember that in Java, a float can only hold a maximum of 8 significant digits, and a float literal has a capital F appended to the number. float z = 20.0F; float a = 1.0e-10F; float x = 10.0F; float b = 2.0e-10F; System.out.println(b - 2 * a + z - x); System.out.println(x + x - z - a); System.out.println(x + x - a - z); System.out.println(b - 2 * (a + z) - x); 10.0-1.0E-10 0.0-50.0 b) The two equations shown below provide one of the roots of the quadratic equation: ax 2 +bx+c = 0. They are both algebraically correct equations. Circle the equation that you would use to calculate x 1 in a Java program in the case where the product of a times c is much smaller than b. x 1 = b + 2 b 2a 4ac x 1 = b + 2c b 2 4ac Why did you choose this equation over the other? (One or two sentences only, please.) The second equation will approach c/b, where the first equation approaches zero when ac << b. The second equation will be less susceptible to roundoff error.

Student Number: Page 3 of 17 Problem 3) [14 marks] You must complete an object hierarchy by writing two classes: Square and Rectangle. You are given the classes: IllegalShapeException, AllSides and a class called TestShapes that shows how your objects must work. You are also given the interface: RequiredAccessorsInterface. The hierarchy is defined by: The class Rectangle must implement RequiredAccessorsInterface. The class Square must extend Rectangle. As always, you are expected to use proper encapsulation practices. Write just the minimum amount of code required to satisfy the TestShapes class. Do not write any mutators, any other constructors than what is required, any other accessors than what is required, or any of the other standard methods, including clone(), equals(), compareto() or tostring(). An illegal dimension is less than or equal to zero. You will have space to write your two classes following this listing of the three supplied classes and the interface. public class IllegalShapeException extends Exception { public IllegalShapeException () { super("\nattempt to create an illegal shape."); // end IllegalShapeException public interface RequiredAccessorsInterface { AllSides getsides (); double getarea(); // end RequiredAccessorsInterface public class AllSides { public double side1, side2; public AllSides(double a) { side1 = a; side2 = 0; public AllSides(double a, double b) { side1 = a; side2 = b; // end AllSides

Student Number: Page 4 of 17 Problem 3, Cont.) public class TestShapes { public static void testaccessors (RequiredAccessorsInterface shape) { System.out.println("\nTesting: " + shape.getclass().getname()); System.out.println("Area = " + shape.getarea()); String s = "Side1 = " + shape.getsides().side1; if (shape.getsides().side2 > 0) s += ", Side2 = " + shape.getsides().side2; System.out.println(s); // end testaccessors public static void main(string[] args) { Square illegalsquare = null, legalsquare = null; Rectangle illegalrectangle = null, legalrectangle = null; // Square try { illegalsquare = new Square(-2.0); catch (IllegalShapeException e) { System.out.println(e.getMessage()); try { legalsquare = new Square(2.0); catch (IllegalShapeException e) { System.out.println(e.getMessage()); testaccessors(legalsquare); // Rectangle try { illegalrectangle = new Rectangle(-2.0, 3.0); catch (IllegalShapeException e) { System.out.println(e.getMessage()); try { legalrectangle = new Rectangle(2.0, 3.0); catch (IllegalShapeException e) { System.out.println(e.getMessage()); testaccessors(legalrectangle); // end main // end TestShapes

Student Number: Page 5 of 17 Problem 3, Cont.) /* Output from TestShapes: Attempt to create an illegal shape. Testing: Square Area = 4.0 Side1 = 2.0 Attempt to create an illegal shape. Testing: Rectangle Area = 6.0 Side1 = 2.0, Side2 = 3.0 */

Student Number: Page 6 of 17 Problem 3, Cont.) public class Rectangle implements RequiredAccessorsInterface { private double sidea, sideb; public Rectangle (double a, double b) throws IllegalShapeException { if (a > 0 && b > 0) { sidea = a; sideb = b; else throw new IllegalShapeException(); // end constructor public AllSides getsides () { return new AllSides(sideA, sideb); // end getsides public double getarea () { return sidea * sideb; // end getarea // end Rectangle public class Square extends Rectangle { public Square (double a) throws IllegalShapeException { super(a, a); public AllSides getsides () { return new AllSides(super.getSides().side1); // end Square

Student Number: Page 7 of 17 Problem 5) [10 marks] Complete the following GUI class. You must add code to the constructor to finish the layout of the two components a label and a command button. Then you must complete the listener class so that the button causes the label to switch between two messages. The window looks like: or: Clicking on the Switch button switches the message on each click. Remember that a button s listener class must implement the ActionListener interface which will force it to have a concrete implementation of the method: public void actionperformed(actionevent e) To set the text of a label, you invoke the settext() mutator method. To add a component to a panel or a JFrame, you invoke the add() method. The listing of the class you must complete begins on the next page. Add code where indicated only, and do not change any of the supplied code. Note that you cannot get this layout by adding the button and label components directly to the frame; you must use a Container component instead (like a JPanel ).

Student Number: Page 8 of 17 Problem 5, Cont.) import javax.swing.jframe; import javax.swing.jbutton; import javax.swing.jpanel; import javax.swing.jlabel; import java.awt.font; import java.awt.borderlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; public class GUIExamProblemWindow extends JFrame { private final int WIDTH = 260; private final int HEIGHT = 140; private JButton switchmessagebutton = new JButton("Switch"); private JLabel messagelabel = new JLabel("ALMOST OVER!"); private boolean messageflag = false; public GUIExamProblemWindow () { super(); setdefaultcloseoperation(jframe.exit_on_close); settitle("gui Problem"); setsize(width, HEIGHT); messagelabel.setfont(new Font("Stencil", Font.PLAIN, 26)); switchmessagebutton.addactionlistener(new MessageButtonListener()); setlayout(new BorderLayout()); // COMPLETE THE CONSTRUCTOR HERE: JPanel bottompanel = new JPanel(); JPanel midpanel = new JPanel(); midpanel.add(messagelabel); bottompanel.add(switchmessagebutton); add(midpanel, BorderLayout.CENTER); add(bottompanel, BorderLayout.SOUTH); // end constructor

Student Number: Page 9 of 17 Problem 5, Cont.) // WRITE THE LISTENER CLASS HERE: private class MessageButtonListener implements ActionListener { public void actionperformed (ActionEvent e) { if (messageflag) messagelabel.settext("almost OVER!"); else messagelabel.settext("happy HOLIDAYS!"); messageflag =!messageflag; // end actionperfomed // end MessageButtonListener // end GUIExamProblemWindow class