Do not turn to the next page until the start of the exam.

Similar documents
Do not turn to the next page until the start of the exam.

PIC 20A GUI with swing

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

Final Exam CS 251, Intermediate Programming December 13, 2017

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

CS 251 Intermediate Programming GUIs: Components and Layout

Midterm assessment - MAKEUP Fall 2010

CS 61B Discussion 5: Inheritance II Fall 2014

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

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

CSC Java Programming, Fall Java Data Types and Control Constructs

CS 180 Fall 2006 Exam II

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Prelim 2. CS 2110, 5:30 PM, November 17, 2016

PIC 20A Number, Autoboxing, and Unboxing

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

Throughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.

UMBC CMSC 331 Final Exam

Window Interfaces Using Swing Objects

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

Introduction to Programming Using Java (98-388)

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

CS165 Practice Final Exam

Index COPYRIGHTED MATERIAL

Graphics User Defined Forms, Part I

More on Objects in JAVA TM

CS Exam 1 Review Suggestions

CMSC 331 Second Midterm Exam

CS165 Practice Final Exam Answer Key

Lecture 5: Java Graphics

1. (5 points) In your own words, describe what an instance is.

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

Lecture 3: Java Graphics & Events

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

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

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

PIC 20A Streams and I/O

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

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

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

5/23/2015. Core Java Syllabus. VikRam ShaRma

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

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.

Final Exam CS 251, Intermediate Programming December 10, 2014

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

UMBC CMSC 331 Final Exam

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

CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7. Question 1. (2 points) What is the difference between a stream and a file?

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Algorithms & Datastructures Laboratory Exercise Sheet 1

Content Area: Mathematics Course: Computer Programming Grade Level: R14 The Seven Cs of Learning

CS 3331 Advanced Object-Oriented Programming Final Exam

PIC 20A Collections and Data Structures

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

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

CS 11 java track: lecture 3

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

VALLIAMMAI ENGINEERING COLLEGE

Name: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron

Swing from A to Z Using Focus in Swing, Part 2. Preface

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

Lesson 3: Accepting User Input and Using Different Methods for Output

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

MIT AITI Swing Event Model Lecture 17

15CS45 : OBJECT ORIENTED CONCEPTS

CSE wi Final Exam 3/12/18. Name UW ID#

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

Selected Java Topics

Objects and Iterators

Class 16: The Swing Event Model

Window Interfaces Using Swing Objects

Introduction to Computing II (ITI 1121) Final Examination

Come & Join Us at VUSTUDENTS.net

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

CIS 120 Final Exam 15 December 2017

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

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

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

Java Programming Lecture 6

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

Full file at

DO NOT. package java.lang; public final class String implements Serializable, Comparable, CharSequence {

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

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

Java Object Oriented Design. CSC207 Fall 2014

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM)

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Declarations and Access Control SCJP tips

CSE331 Fall 2014, Final Examination December 9, 2014 Please do not turn the page until 2:30. Rules:

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

Lecture 14 Summary 3/9/2009. By the end of this lecture, you will be able to differentiate between errors, exceptions, and runtime exceptions.

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.

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

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

In this lab we will practice creating, throwing and handling exceptions.

Transcription:

Principles of Java Language with Applications, PIC20a E. Ryu Fall 2017 Final Exam Monday, December 11, 2017 3 hours, 8 questions, 100 points, 9 pages While we don t expect you will need more space than provided, you may continue on the back of the pages. This exam is closed book and closed notes. Student name: Teaching staff signature: Do not turn to the next page until the start of the exam.

1. (2 points) In what version of Java was default methods for interfaces introduced? A. Java 5 B. Java 6 C. Java 7 D. Java 8 E. Java 9 2. (2 points) The antonym (the opposite) of functional programming is A. procedural programming. B. imperative programming. C. object oriented programming. 3. (2 points) The utility class Collections has a function max, which returns the maximum element of a Collection<?> based on a input Comparator<?>. Which of the following is a valid signature of Collections.max? A. public static <T > T max ( Collection <? super T > coll, Comparator <? super T > comp ) B. public static <T > T max ( Collection <? extends T > coll, Comparator <? extends T > comp ) C. public static <T > T max ( Collection <? extends T > coll, Comparator <? super T > comp ) D. public static <T > T max ( Collection <? super T > coll, Comparator <? extends T > comp ) 4. (2 points) You can catch a RuntimeException with a catch block. A. True B. False 5. (2 points) Explain the term autoboxing in one or two sentences. Page 2

6. (30 points) Write class IteratorReader, which reads characters from an Iterator<Character>. Make IteratorReader inherit the redacted version of Reader, which is provided in the documentation; the actual class java.io.reader has more functionality (and therefore more to override to inherit) but we simplified it a bit. import java.io. Reader ; import java. util.*; public class Test { public static void main ( String [] args ) throws Exception { String str = " Hello world "; // convert str to List < Char > ArrayList < Character > c_ list = new ArrayList < >(); for ( int i =0; i<str. length (); i ++) c_list. add ( str. charat (i )); Reader r = new IteratorReader ( c_list. iterator ()); while ( true ) { int nextchar = r. read (); if ( nextchar == -1) break ; System. out. print (( char ) nextchar ); r. close (); An Iterator<Character> allows us to iterate through a sequence of characters. IteratorReader is a wrapper class. The read() method of IteratorReader retrieves the same sequence of characters one could obtain with the Iterator<Character> provided through the constructor. The specification of IteratorReader is as follows. IteratorReader has one public constructor public IteratorReader ( Iterator < Character > itr ) which appropriately initializes the IteratorReader based on the input Iterator<Character>. IteratorReader overrides the method public int read () throws IOException read() returns a single character that represents a letter or a digit. If there are no more such characters to read, return -1. IteratorReader overrides the method public void close () throws IOException which nulls any reference of the Iterator<Character> provided through the constructor. In other words, the IteratorReader will not have access to the Iterator<Character> after close() has been called. Finally, write a short paragraph (3 sentences at most) explaining when IteratorReader throws any Exceptions and justifying why this is a sensible design choice. Page 3

Page 4

7. (30 points) You are a journalist working for a newpaper company with a long history. Out of curiosity, you would like to look up the most recent article that uses the archaic word thou. Articles are represented as Article Objects. public class Article { public string title ; public string fulltext ; public int publicationyear ; public int publicationmonth ; public int publicationdate ; public string author ; Assume fulltext contains English letters and usual proper punctuation. Assume the ArrayList<Article> corpus contains all articles ever published in your paper. public class Test { public static void main ( String [] args ) { ArrayList < Article > corpus ; // somehow load corpus... // start writing code here... Write code that looks through corpus and finds the most recent Article with the word thou in its text or title. Output the search result in any reasonable manner using System.out. If two or more Articles are the most recent, then you can output any one of them. In other words, you can output any one of the winners. If no article contains the word thou, say so. You may not use the methods indexof(...) or lastindexof(...) of class String. Hint. Make sure your code does not think words like thousand or lighthouse are matches for thou. Page 5

Page 6

8. (30 points) The following GUI // file RandomGUI. java import javax. swing.*; import java. awt.*; public class RandomGUI { private JFrame frame = new JFrame (" Random GUI "); private JLabel label = new JLabel (" X"); private JButton button1 = new JButton (" Roll dice "); private JButton button2 = new JButton (" Flip coin "); public RandomGUI () { frame. setdefaultcloseoperation ( JFrame. DISPOSE_ON_CLOSE ); label. sethorizontalalignment ( SwingConstants. CENTER ); frame. getcontentpane (). add ( label, BorderLayout. CENTER ); frame. getcontentpane (). add ( button1, BorderLayout. SOUTH ); frame. getcontentpane (). add ( button2, BorderLayout. NORTH ); frame. setsize (300, 200); frame. setvisible ( true ); when run with // file Test. java public class Test { public static void main ( String [] args ) { new RandomGUI (); creates the window Page 7

At this point, nothing happens when we click the buttons. Add to and modify the provided code so that clicking the top button changes the text X to a random choice of Heads and Tails and clicking the bottom button changes the text X to a random integer between 1 and 6. The completed GUI should display something like when the button is clicked. Use lambda expressions for this problem. If you do not use lambda expressions, you will get partial credit of up to 20 points. Page 8

Page 9