CS 1316 Exam 3 Fall 2009

Similar documents
CS 1316 Exam 2 Fall 2009

CS 1316 Exam 2 Summer 2009

CS Exam 3 - Spring 2010

CS Exam 3 - Spring 2010

CS 1316 Exam 1 Summer 2009

Exam Percentage: / 55 = %

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

CS Exam 2 - Spring 2010

CS 1301 Exam 1 Answers Fall 2009

Dr. Hikmat A. M. AbdelJaber

CS 1301 Exam 1 Fall 2009

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Graphical User Interfaces. Comp 152

CS Exam 1 Review Suggestions

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

CS 1301 Exam 1 Fall 2010

Top-Level Containers

To gain experience using GUI components and listeners.

This exam has 10 pages including the title page. Please check to make sure all pages are included.

Part I: Learn Common Graphics Components

2110: GUIS: Graphical User Interfaces

Graphical User Interfaces. Swing. Jose Jesus García Rueda

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

Graphic User Interfaces. - GUI concepts - Swing - AWT

CS 216 Exam 1 Fall SOLUTION

CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

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

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

Agenda. Container and Component

Question Possible Points Earned Points Graded By GUI 22 SQL 24 XML 20 Multiple Choice 14 Total Points 80

Introduction. Introduction

CS 1301 Exam 2 Fall 2013

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

CS 1301 Exam 1 Fall 2010

Your (printed!) Name: CS 1803 Exam 3. Grading TA / Section: Monday, Nov. 22th, 2010

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

CS 2316 Exam 4 Fall 2012

CS 2316 Exam 4 Fall 2012

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

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

Containers and Components

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

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

CS Name : Grading TA:

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

INTRODUCTION TO (GUIS)

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

== isn t always equal?

Question: Total Points: Score:

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

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

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

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

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

Question: Total Points: Score:

CS 1301 Exam 3 Spring 2014

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

CS 1301 Exam 1 Fall 2011

CS 1301 Exam 2 A Fall 2015

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSCI 201L Midterm Written SOLUTION Fall % of course grade

Window Interfaces Using Swing Objects

CS 1301 Exam 1 Spring 2014

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

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

Laying Out Components. What is Widget Layout?

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

CS Fall Homework 5 p. 1. CS Homework 5

+ Abstract Data Types

Instructor: Yu Wang 11/16/2012

CS 2316 Exam 1 Spring 2014

Lecture 02, Fall 2018 Friday September 7

CS 1301 Exam 1 Spring 2014

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

ITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity

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

Review sheet for Final Exam (List of objectives for this course)

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

CS 2316 Exam 3 Fall 2012

CS 2316 Exam 3 Fall 2011

Example: Building a Java GUI

Question: Total Points: Score:

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

CS 2316 Exam 4 Fall 2011

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

Example: Building a Java GUI

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CS 2316 Exam 1 Spring 2013

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

AP CS Unit 11: Graphics and Events

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Window Interfaces Using Swing Objects

Eclipsing Your IDE. Figure 1 The first Eclipse screen.

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

Transcription:

1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 3 Fall 2009 Section/Problem Points Earned Points Possible 1. Terms & Concepts 33 2. Short Answers 12 3. Trees 9 4. Tree Question 5 5. Queue Operations 3 6. Code Comprehension GUI 10 7. Write Code: Musical Instrument 15 Total Points: 87

2 / 8 Your Name: 1. Terms & Concepts (33 points) For each of the terms below, write 1 or 2 sentences defining the term and proving you understand what your definition means. You may include an example if you think it will help your explanation. Be concise and precise. 1. abstract (super) class A class meant to be subclassed that can not be instantiated 2. anonymous inner class An unnamed class created inside of another class. Typically created as part of a GUI to handle user interface events. 3. binary search tree A binary tree arranged so that all values to the left of the current node are smaller than it's value, and all values to the right of the current node are equal to or greater than the current node's value. Provides log2(n) search time. 4. final static variable A constant variable that can't be changed. 5. interface A listing of method signatures (without bodies!) that acts as a contract. If a class says that it implements an interface, it must define each of the specified methods. 6. layout manager a java GUI object that handles the layout of subcomponents within a java GUI Component. Examples are BoxLayout, FlowLayout, etc. 7. leaf node Nodes in a tree that do not have any children of their own. 8. queue An Abstract Data Type (ADT) that must implement two methods (enqueue and dequeue). Items placed in a queue using the enqueue method emerge from the queue in a FIFO (First In First Out) order when the dequeue method is called. 9. static method A method that belongs to a class, and is shared by all objects instantiated from that class. Class methods can be called directly from the class, and do not require an object to be instantiated before they can be used. However, static methods can not access object variables. 10.this (keyword) A reference to the current object. (How methods know which object they are associated with.) 11.void (keyword) A keyword that specifies "nothing", used to indicate that a method does not take any parameters, or does not return anything.

3 / 8 Your Name: 2. Short Answer ( 12 points) a. What causes a null pointer exception? (2pts) The Java runtime (JVM) throws a Null Pointer exception when the user's code tries to access something in an object (field or method) using a reference that is not pointing to an object. (Instead, the reference is actually pointing to nothing, or "null". b. What is the difference between a compiler error and a runtime exception? Give an example of each. (3pts) A compiler error (syntax error) is caused because something about your code is incorrect, and not valid Java syntax. A runtime error is caused when your code does something that is incorrect, such as dividing by zero, trying to open a file that does not exist, or trying to access an object field or method using a reference that points to null instead of an object. c. Multiple Choice: Interfaces contain the following: (check all that apply) (1pt) O method signatures <CORRECT ANSWER 1> O method bodies O static, final fields <CORRECT ANSWER 2> O instance variables d. What is the main difference between a continuous and a discrete event simulation? (3pts) A continuous simulation evaluates the model at every timestep, while a discrete event simulation calculates the time of the next interesting event and skips to it. e. How is sampled sound stored in a computer? What does each sample represent? (3pts) The amplitude of a sound wave at each sample point in time is stored using a number between -32K and 32K. For example, 44100Hz sampling takes that many samples a second.

4 / 8 Your Name: 3. Trees ( 9 points) a. If the in-order traversal of the balanced binary search tree T is: M N O P Q R S, draw the tree: P N R M O Q S Grading: 3 if correct, 0 if not balanced. b. If the pre-order traversal of the binary search tree T is: F E D C B A, draw the tree: One valid example is a tree that extends only to the left: F E D C B A Grading: 3 if correct, (-1 point for each node pairs that are out of order) c. Traverse the following tree using post-order traversal. Write out each letter.! V T O E G I L ILOVEGT! Grading: 3 points if all correct. 1 point if "GT" are present in the correct order.

5 / 8 Your Name: 4. Tree Question (5 points) Consider the method X: public static int X( TreeNode t) { if (t.left == null && t.right == null) { return t.data; else if (t.left == null) { return Math.min( t.data, X(t.right) ); else if (t.right == null) { else { // end X return Math.min( t.data, X(t.left) ); return Math.min( Math.min( t.data, X(t.left) ), X(t.right) ); If you call X giving it a non-empty tree, what statement can you make about the value that X returns? The code will return the minimum element in the tree. Grading: 5 points for the correct answer. 4 points if they say it returns the minimum of the leaf nodes. 3 points if they indicate they know what it will do, but don't make a correct statement about what the value X returns. 0 if they are wrong. 5. Queue operations (3 Points) Examine the following series of code statements. Draw the contents of the queue after the following code executes. Clearly mark the front and back of the queue. Queue x = new Queue(); x.enqueue("a"); x.enqueue("b"); x.enqueue("c"); String temp1 = x.dequeue(); String temp2 = x.dequeue(); x.enqueue("d"); Head: C D :Tail (Not required, but if they specify that temp1=a and temp2=b that's fine) 1 point for each letter (C/D), 1 point for the correct ordering of C,D. ( 1 point for each other letter like A,B)

6 / 8 Your Name: 6. Code Comprehension - GUI's (10 points) Draw the GUI that will be made when the following code is run. If no text would be shown on the widget when the GUI is displayed, write the name of the type of widget instead (button, slider, etc) import java.awt.borderlayout; import java.awt.gridlayout; import javax.swing.*; public class Test3GUI extends JFrame{ public Test3GUI(){ super("test3gui"); this.getcontentpane().setlayout(new BorderLayout()); JLabel label1 = new JLabel("Lable1"); JTextField text = new JTextField(20); JButton b1 = new JButton("Button1"); JButton b2 = new JButton("Button2"); JButton b3 = new JButton("Button3"); JSlider slider = new JSlider(); JComboBox cb = new JComboBox(); JPanel p1 = new JPanel(); p1.setlayout(new GridLayout(2,1)); this.add(label1, BorderLayout.NORTH); p1.add(b1); p1.add(b2); this.add(p1, BorderLayout.EAST); this.add(cb, BorderLayout.WEST); this.add(slider, BorderLayout.SOUTH); this.add(text, BorderLayout.CENTER); this.add(b3, BorderLayout.CENTER); this.pack(); this.setvisible(true); public static void main(string[]args){ Test3GUI gui = new Test3GUI(); // end class Grading: one point for each of the following elements: Frame name (Test3GUI), border layout (everything being in the right spots), label1, combo box, slider, grid layout / panel, button 1, button 2, button 3, textfield (hidden behind button3)

7 / 8 Your Name: 7. Create an Object: Musical Instrument (15 points) You are given the following interface: public interface MusicalInstrument { // returns the sound of the instrument public Sound getsound(); //returns the name of the musical instrument public String getname(); Your task is to create a new class called Piano that fully implements the MusicalInstrument interface. Your new class should also contain the following: A public instance variable of type Sound A constructor that accepts a single parameter of type Sound and sets the sound instance variable to the input sound. An additional method called appendnplay that takes in a sound A and a double factor, and does not return anything. This method should append the input sound to the instance variable sound. After it does that, it must also modify the volume of the resulting sound by the factor parameter. (Multiply each sound sample by the factor, and put the new value back into the sample.) Once you have completed your manipulations, play the resulting sound! Methods in the Sound class that you might find useful: Sound append ( Sound appendsound) void play() SoundSample [] getsamples() Methods in the SoundSample class that you may find useful: int getvalue() void setvalue(int) Write your code on the back of this page:

8 / 8 Your Name: public class Piano implements MusicalInstrument { public Sound mysound; public Piano (Sound s) { mysound = s; public Sound getsound() { return mysound; public String getname() { return Piano ; public void appendnplay(sound A, double factor) { Sound newsound = mysound.append(a); SoundSample[] ss = newsound.getsamples(); for (int i = 0; i < ss.length; i++) { int currentvalue = ss[i].getvalue(); ss[i].setvalue(currentvalue * factor); newsound.play(); Grading: 5 pts - Implementing the interface (1 for "implement", 2 for each function) 1 - Class variable mysound & associated constructor 9 - for Append & Play 1 - Header correct 2 - Appending input parameter to mysound 1- Storing result in a new Sound variable 2 - Getting an array of Sound Samples out of the new sound 2 - Apply the "factor" to the sound samples and saving it back into the samples 1 - play the sound.