CSCI 201L Midterm Written SOLUTION Summer % of course grade

Similar documents
CSCI 201L Midterm Written Summer % of course grade

CSCI 201L Written Exam #1 - SOLUTION Fall % of course grade

CSCI 201L Written Exam #1 Fall % of course grade

CSCI 201L Midterm Programming. Fall % of course grade

CSCI 201L Midterm Written Fall % of course grade

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

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 SOLUTION Fall % of course grade

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.

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.

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

COMP16121 Sample Code Lecture 1

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.

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

CSCI 201L Final Written SOLUTION. 13% of course grade

CMP 326 Midterm Fall 2015

Trees CSCI 201 Principles of Software Development

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.

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

Graphical User Interface

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

CSCI 201L Written Exam #1 Fall % of course grade

CS 251 Intermediate Programming GUIs: Event Listeners

Dr. Hikmat A. M. AbdelJaber

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012

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

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

JFrame & JLabel. By Iqtidar Ali

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CSIS 10A Assignment 7 SOLUTIONS

Lecture 3: Java Graphics & Events

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

Graphical User Interfaces 2

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

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.

H212 Introduction to Software Systems Honors

The class definition is not a program by itself. It can be used by other programs in order to create objects and use them.

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

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

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

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

CSCI 201L Written Exam #1 Fall % of course grade

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

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

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

Graphical User Interfaces 2

Multimedia Programming

Graphic User Interfaces. - GUI concepts - Swing - AWT

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

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

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

PART 22. Java GUI Library SWT GUI Library SWING GUI Library Swing First Program

PIC 20A GUI with swing

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

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

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

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

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

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition

Lecture 5: Java Graphics

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.

Dr. Hikmat A. M. AbdelJaber

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

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

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

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

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

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

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

Java Application Development

AP CS Unit 11: Graphics and Events

Java GUI Design: the Basics

Declarations and Access Control SCJP tips

Graphical User Interfaces 2

Graphical interfaces & event-driven programming

Final Score ID Extra Credit. 15% of course grade

COMPSCI 230. Software Design and Construction. Swing

Answer on question #61311, Programming & Computer Science / Java

public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); }

IT101. Graphical User Interface

Workbook 7. Remember to check the course website regularly for announcements and errata:

Java Never Ends MULTITHREADING 958 Example: A Nonresponsive GUI 959

20 Most Important Java Programming Interview Questions. Powered by

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Selected Questions from by Nageshwara Rao

CS 61B Discussion 5: Inheritance II Fall 2014

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

Getting started with Java

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

Swing from A to Z Some Simple Components. Preface

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

Transcription:

CSCI 201L SOLUTION Summer 2016 10% of course grade 1. Abstract Classes and Interfaces Give two differences between an interface and an abstract class in which all of the methods are abstract. (0.5% + 0.5%) Interfaces are Java s solution to only having single inheritance, though you can inherit from more than one object through interfaces. Abstract classes still inherit from the Object class (or possibly other classes), and all of the methods in those classes are not abstract. Abstract classes can have variables that are not static and final. Other answers could be acceptable. 2. Serialization If an object does not implement the Serializable interface, a NotSerializableException will be thrown when trying to serialize that object. If an object does implement the Serializable interface, there are still two types of variables in the class that will not be serialized. State the two types of variables that will not be serialized and explain why they are not serialized. (0.5% + 0.5%) Transient variables are specifically defined so that they will not be serialized. Static variables are not serialized because classes are not serialized but rather object are serialized. Static variables are not associated with an object but are associated with a class. 3. Exception Handling Java, unlike C++, has both checked and unchecked exceptions. Explain why unchecked exceptions in Java do not need to be handled by a corresponding try block. (0.5%) Unchecked exceptions can be handled by good programming practices instead of exception handling. Exception handling is a very expensive operation (takes about 10x as long to execute as good programming practice), so handling unchecked exceptions through exception handling should be avoided. 1/5

4. GUI Programming - Draw the GUI that is generated by the following code. (1.0%) Assume the image usc.jpg is Assume the image ucla.jpg is import java.awt.borderlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.box; import javax.swing.boxlayout; import javax.swing.buttongroup; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jradiobutton; public class Problem5 extends JFrame { private JLabel jl, jl1, jl2; private ImageIcon ii, ii1; public Problem5() { super("problem 5"); setsize(200, 300); setlocation(500, 300); setdefaultcloseoperation(jframe.exit_on_close); JPanel jp = new JPanel(); jp.setlayout(new BoxLayout(jp, BoxLayout.X_AXIS)); ii = new ImageIcon("usc.jpg"); ii1 = new ImageIcon("ucla.jpg"); jl = new JLabel(ii); jp.add(box.createglue()); jp.add(jl); jl1 = new JLabel("USC"); jp.add(jl1); jp.add(box.createglue()); jl2 = new JLabel(ii); jp.add(jl2); add(jp, BorderLayout.CENTER); JRadioButton jrb = new JRadioButton("USC", true); JRadioButton jrb1 = new JRadioButton("UCLA", false); ButtonGroup bg = new ButtonGroup(); bg.add(jrb); bg.add(jrb1); JPanel jp1 = new JPanel(); jp1.add(jrb); jp1.add(jrb1); add(jp1, BorderLayout.NORTH); setvisible(true); public static void main(string [] args) { new Problem5(); 2/5

5. Inheritance There are two errors in the following code. Describe the errors and modify the code to fix them. (2.0%): 1 interface C { 2 public int m(); 3 public abstract int n(); 4 5 6 abstract class D implements C { 7 public int m() { 8 return 3; 9 10 11 12 abstract class E extends D { 13 public int n() { 14 return 4; 15 16 public int o() { 17 return 5; 18 19 20 21 class F extends E { 22 23 24 25 public class Problem3 { 26 public static void main(string [] args) { 27 F f = new F(); 28 f.m(); 29 f.n(); 30 f.o(); 31 E e = new E(); 32 e.m(); 33 e.n(); 34 e.o(); 35 C c = new F(); 36 c.m(); 37 c.n(); 38 c.o(); 39 40 0.5% E is an abstract class and therefore can t be instantiated. Fix (0.5%) The line could be changed to: E e = new F(); 0.5% The method o is undefined for class C. The only methods that can be called on an object are those which are defined in the compile-time type of the object. Fixes (0.5% for one of the following) 1. We could add an abstract method o into interface C. 2. We could change line 35 to say E e = new F(); 3/5

6. Inner Classes KeyListener is an interface that contains three methods keypressed, keytyped, and keyreleased, all three of which take a KeyEvent as a parameter. Write the code using an anonymous inner class to add a KeyListener to a JTextField that prints out Hello to the command line when a user releases the h key on the keyboard. (1.5%) JTextField jtf = new JTextField(); jtf.addkeylistener(new KeyAdapter() { public void keyreleased(keyevent ke) { if (ke.getkeycode() == KeyEvent.VK_H) { System.out.println("hello"); ); 7. Garbage Collection The garbage collector provides one of the biggest advantages to Java over C++, though many Java developers inaccurately believe that a Java program cannot crash due to running out of memory. Write a snippet of code that would cause a Java program to throw an OutOfMemoryError. (1.0%) String str = ; while(true) { str += a ; Other answers may be acceptable. 4/5

8. Software Engineering Scrum is arguably the most popular software engineering methodology in use right now. Give two reasons why you think that is the case. (0.5% + 0.5%) Software engineering has turned toward needing more frequent releases of products, making agile methodologies more useful. Web and mobile development has continuous updates to keep the users interested, so more frequently release cycles are needed. Agile methodologies focus on people and customers rather than merely focusing on processes and documentation. This makes programmers happier. Programming teams with good programmers tend to desire scrum since there is a shared sense of responsibility. Team work over individual work. Other answers could be acceptable. 9. Anonymous Inner Classes The following code may appear to some people to be instantiating an interface, which we learned is not possible in Java. If the following code does not compile, explain why and fix it. If the following code does compile, explain what is happening on lines 7-14. (1.0%) 1 public class Problem6 { 2 public Problem6(I i) { 3 i.a(); 4 i.b(); 5 6 public static void main(string [] args) { 7 new Problem6(new I() { 8 public void a(float f) { 9 System.out.println("a"); 10 11 public void b() { 12 System.out.println("b"); 13 14 ); 15 16 17 interface I { 18 void a(int i); 19 void b(); 20 0.5% The method a(int) is not overridden in the anonymous inner class, so it will need to be abstract and cannot be instantiated. Fixes (0.5% for one of the following) 1. Change int to be float on line 18, or 2. Change float to be int on line 8 5/5