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

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

CS Exam 1 Review Suggestions

AP CS Unit 11: Graphics and Events

MIT AITI Swing Event Model Lecture 17

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.

Come & Join Us at VUSTUDENTS.net

Last Name: Circle One: OCW Non-OCW

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

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

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003

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

CS 11 java track: lecture 3

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

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

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

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

SINGLE EVENT HANDLING

Packages: Putting Classes Together

F I N A L E X A M I N A T I O N

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

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

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

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

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003

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

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

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

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

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!

We are on the GUI fast track path

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

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

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

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.

Graphics User Defined Forms, Part I

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

The Nervous Shapes Example

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

RAIK 183H Examination 2 Solution. November 10, 2014

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

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2

Graphical User Interface (GUI)

Window Interfaces Using Swing Objects

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

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

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

2IS45 Programming

Final Exam May 21, 2003

H212 Introduction to Software Systems Honors

Keyword this. Can be used by any object to refer to itself in any class method Typically used to

RAIK 183H Examination 2 Solution. November 11, 2013

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

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

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

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

IT101. Graphical User Interface

Advanced Java Unit 6: Review of Graphics and Events

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

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

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

Chapter 6: Inheritance

Object-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

Java Help Files. by Peter Lavin. May 22, 2004

Swing from A to Z Some Simple Components. Preface

CS 180 Fall 2006 Exam II

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

Swing. By Iqtidar Ali

Implementing Graphical User Interfaces

System.out.print(); Scanner.nextLine(); String.compareTo();

Reviewing OO Concepts

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

The Decorator Pattern. Design Patterns In Java Bob Tarr

Contents Chapter 1 Introduction to Programming and the Java Language

Midterm assessment - MAKEUP Fall 2010

CS Exam 3 - Spring 2010

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

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

Programmierpraktikum

Window Interfaces Using Swing Objects

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

Today. Book-keeping. Inheritance. Subscribe to sipb-iap-java-students. Slides and code at Interfaces.

Reviewing OO Concepts

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

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

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

1 Looping Constructs (4 minutes, 2 points)

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

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

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

Chapter 13 Lab Advanced GUI Applications

Final Examination Semester 2 / Year 2011

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

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

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Transcription:

First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand your answer, you will receive 0 points for that question. This exam has 6 parts worth a total of 100 points. Section 1 Abstract Classes and Interfaces (35 points) 1. (14 points) Circle True or False True / False If a class uses an interface, we use the keyword extends. True / False An interface contains a list of methods that every class which implements this interface must have. True / False An abstract class can be instantiated. True / False If there exists an interface called Animal, the following statement will compile successfully: Animal a1 = new Animal(); True / False If there exists an interface called Animal, and a class called Lizard which implements Animal, the following statement will compile successfully: Animal a1 = new Lizard(); True / False You can implement methods in the body of an abstract class. True / False A class can be the direct subclass of several classes. True / False A class can implement several interfaces. 2. (6 points) There are three Java files between the horizontal lines on the next page: Shape.java, Rectangle.java, and Square.java. Each is in a separate package. Add import statements to the files so that they compile. 3. (3 points) Implement the Square constructor on page 3. 4. (12 points) Looking at the classes on page 3, circle the output of the following code segments or circle "error" if the code would generate a compiling or execution error. Square s = new Square(3); System.out.println(s.area()); a) 3 b) 9 c) error Rectangle r = new Rectangle(3, 3); System.out.println(r.area()); a) 3 b) 9 c) error Shape p = new Shape(3, 3); System.out.println(p.area()); LAST NAME, FIRST NAME: 1 of 7

a) 3 b) 9 c) error Square s = new Square(3); System.out.println(s.toString()); a) square b) rectangle c) error Rectangle r = new Square(3); System.out.println(r.toString()); a) square b) rectangle c) error Shape p = new Square(3); System.out.println(p.toString()); a) square b) rectangle c) error LAST NAME, FIRST NAME: 2 of 7

package shapes; public interface Shape { public int area(); package rectangles; public abstract class Rectangle implements Shape { private int width, height; public Rectangle(int width, int height) { this.width = width; this.height = height; public int area() { return width * height; public String name() { return "rectangle"; package squares; public class Square extends Rectangle implements Shape { public Square(int size) { public String name() { return "square"; LAST NAME, FIRST NAME: 3 of 7

Section 2 Exceptions (12 points) 1. (4 points) Create a checked exception class called DivideByZeroException. 2. (4 points) Change this method so that it throws a DivideByZeroException with an appropriate message if b is zero. public static double divide(double a, double b) { return a / b; 3. (4 points) Change this method so that it catches the DivideByZeroException thrown by divide and prints the message "the divisor is zero" if it is thrown. public static void printquotient(double a, double b) { System.out.println(divide(a, b)); LAST NAME, FIRST NAME: 4 of 7

Section 3 There is NO Section 3 Section 4 IO and Parsing (12 points) 1. (2 points) In order to read/write files in Java, you should import which package? a) javax.swing b) java.io c) java.awt d) java.util 2. (2 points) To write to a byte stream, you should use a class that extends which of the following abstract classes? a) Writer b) Reader c) InputStream d) OutputStream 3. (2 points) To read from a character stream, you should use a class that extends which of the following abstract classes? a) Writer b) Reader c) InputStream d) OutputStream 4. (6 points) Complete the method proddoubs below. It expects a String argument containing doubles separated by! symbols and should returns the product of those doubles. For example, when passed the String "2.5!1.0!8.1", it should return 20.25. You can assume java.util.* has been imported. public static double proddoubs(string doubstring) { LAST NAME, FIRST NAME: 5 of 7

Section 5 Swing (21 points) 1. (2 points) In order to create graphical interfaces in Java, you should import which packages? a) java.awt.event, javax.swing b) java.util c) java.util, javax.swing d) java.io, java.swing 2. (2 points) What does the acronym GUI stand for? 3. (2 points) What are the pixel coordinates of the top left corner of your screen? 4. (3 points) Briefly describe how the Flow Layout Manager lays out its components. 5. (12 points) Match the following Swing component with what it is used for. You may write the letter of the answer in the line next to the component: Component Use 1. JFrame A) Generated when a JButton is clicked 2. JComponent B) A top level container 3. JLabel C) Provides space for the user to type into 4. JPanel D) All the Swing components inherit from this class 5. JTextField E) An intermediate container 6. ActionEvent F) Displays text that the user cannot edit LAST NAME, FIRST NAME: 6 of 7

Section 6 Classes (20 points) On the next page write a class to represent a football team in a package called football. We want to be able to access the class FootballTeam from any package. The team has the following properties, which cannot be accessed outside of the class. - name of the team - number of wins - number of losses Write a constructor that accepts the name of the team, the number of wins, and the number of losses as arguments and sets the class properties to those values. This constructor should be accessible from any package. Write a second constructor that takes only the name of the team as an argument. This constructor should set the name of the team to the argument and the set the number of wins and losses to 0. (Hint: The body of this constructor should be one line and it should call the first constructor.) This constructor should be accessible from any package. Write methods that return the name of the team, the number of the wins, and the number of losses. These methods should be accessible from any package. Next write a method to increase the numbers of wins by 1 and another method to increase the number of losses by one. These methods should only be accessible from inside the football package. Write a method that returns true when a team has a "good" record, meaning the team has more wins than losses. This method should be accessible from any package. Finally, add a main method to the FootballTeam class. In the main method, construct a FootballTeam named "AITI" with 3 wins and 5 losses. Call the method that returns true when the team has a good record and print out the result. Now make three calls to the method that increases the number of wins by 1. Lastly, call the "good record" method again and print out the result. LAST NAME, FIRST NAME: 7 of 7