CSE 11 Midterm Fall 2008

Similar documents
CSE 11 Midterm Fall 2009

CSE 11 Midterm Fall 2012

CSE 11 Final Fall 2009

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

CSE 143 SAMPLE MIDTERM

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Lecture Set 4: More About Methods and More About Operators

CSE 8B Final Exam Fall 2015

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Final CSE 131B Spring 2004

CS111: PROGRAMMING LANGUAGE II

University of Massachusetts Amherst, Electrical and Computer Engineering

Lecture Set 4: More About Methods and More About Operators

Final Exam. COMP Summer I June 26, points

Points Missed on Page page 1 of 8

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

WES-CS GROUP MEETING #9

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

McGill University School of Computer Science COMP-202A Introduction to Computing 1

COMP-202: Foundations of Programming. Lecture 10: Method Overloading and Passing Objects to Methods. Sandeep Manjanna, Summer 2015

Chapter 4 Defining Classes I

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)

ESC101 : Fundamental of Computing

CSE 5A Final Fall 2006

Fall 2013 Program/Homework Assignment #2 (100 points) -(Corrected Version)

Computer Programming, I. Laboratory Manual. Final Exam Solution

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

Final CSE 131B Spring 2005

COS 126 General Computer Science Fall Written Exam 1

University of Palestine. Mid Exam Total Grade: 100

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

CSE 143 SAMPLE MIDTERM SOLUTION

Programming Assignment 2 (PA2) - DraggingEmoji & ShortLongWords

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

CS212 Midterm. 1. Read the following code fragments and answer the questions.

I. True/False: (2 points each)

CS 307 Midterm 1 Fall 2007

Introduction to Computer Science I Spring 2010 Sample mid-term exam Answer key

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Selected Questions from by Nageshwara Rao

CS 139 Practice Midterm Questions #2

CSE 131 Introduction to Computer Science Fall Exam II

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

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Programming Assignment 3 ( 100 Points ) START EARLY!

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

CS Problem Solving and Object-Oriented Programming

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CSE 143. Lecture 9: introduction to recursion reading: 12.1

Java Memory Management

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

CS 1316 Exam 1 Summer 2009

Fall 2002 Page 1 of 9 READ THIS NOW!

CS 134 Midterm Fall 2012

Midterm Solutions. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Chapter 6 Introduction to Defining Classes

Classes. Integer Division. Thursday, October 23, March 13, 2008

Section 2.2 Your First Program in Java: Printing a Line of Text

Lecture 8 CSE11 Fall 2013 While Loops, Switch Statement, Simplifying Conditionals

AP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s).

Scope. Dragging Algorithm Revisited. Tuesday, October 28, October 28, 2008

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Final Exam COMP Fall 2004 Dec 16, 2004

Introduction to Programming Using Java (98-388)

CSCI 1226 Sample Midterm Exam

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

cs Java: lecture #6

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Solutions to Sample JAC444 Midterm Test

AP CS Unit 6: Inheritance Notes

Programming Assignment 1: CS11TurtleGraphics

CS 101 Exam 2 Spring Id Name

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Full file at

COS 126 General Computer Science Spring Written Exam 1

Programming: You will have 6 files all need to be located in the dir. named PA4:

CSIS 10A Practice Final Exam Name:

NATIONAL UNIVERSITY OF SINGAPORE

Practice Midterm 1. Problem Points Score TOTAL 50

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

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

Lecture 9 CSE11 Fall 2013 Active Objects

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

Introduction to Computer Science II (CSI 1101)

CSE 70 Final Exam Fall 2009

1. What does the following code fragment write to the monitor?

Lecture 6 CSE 11 Fall 2013

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

Problem Grade Total

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

Computer Science 1 Ah

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Distinguish between a class and an object

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

Transcription:

Signature cs11f Name Student ID CSE 11 Midterm Fall 2008 Page 1 (10 points) Page 2 (22 points) Page 3 (23 points) Page 4 (17 points) Page 5 (12 points) Total (84 points = 80 base points + 4 points EC [5%])

(Partial) Operator Precedence Table Operators Associativity * / % left to right + - left to right < <= > >= left to right ==!= left to right && left to right left to right = right to left 1) Which of the following are not valid Java identifiers? (Circle your answer(s).) 1stAndTen double_down First&Ten main choice? Upper-Case five5five _420_ 2) Using the operator precedence table above, evaluate each expression and state what gets printed. Remember short-circuit evaluation with && and. int x = 6; int y = -2; int z = 13; boolean b =!(x 6 < y z == 2 * x + 1); System.out.print( "b = " + b ); b = (x + y < z 4 * y + z > x) && x > y; System.out.print( "b = " + b ); x = z + x % 4 + y * 2; System.out.print( "x = " + x ); 3) What gets printed with each of the following statements? int a = 1; int b = 3; int c = 5; System.out.println( a + (b + c) + " = " + (a + b) + c ); System.out.println( (a + b + c) + " = " + a + b + c ); System.out.println( (a + b) + c + " = " + a + (b + c) ); 1

4) Write a single method that draws a filled circle on the canvas when the mouse is clicked. The circle should be 100 by 100 pixels centered at the point of the mouse click. Here is the signature for the FilledOval constructor: FilledOval( double x, double y, double width, double height, DrawingCanvas canvas) 5) Assume we have a Java source file named Tunes.java and it uses at least one class in the objectdraw library. Write the full Unix command to compile this Java program. This command will produce a file named Write the full Unix command to run this as a Java application. Assume we have correctly written a Tunes.html file. Write the full Unix command to run the above program as an applet. 6) What gets printed in the following program fragment? final int MAX = 4; int i = 2; int j; while ( i++ < MAX ) j = 7; while ( --j > MAX ) System.out.println( i + " " + j ); System.out.println( i + " " + j ); 2

7) What output is produced by the following program? 1 public class Test7 2 3 private int a; 4 private boolean b; 5 private static int c = 42; 6 public static void main( String[] args ) 7 8 Test7 ref = new Test7(); 9 ref.method1( 5 ); 10 11 public Test7() 12 13 a = 1; 14 15 public void method1( int x ) 16 17 int a = x; 18 int b; Output: this.a = this.b = c = b = a = a = b = c = this.a = this.b = method2() result = 19 b = this.a + 2; 20 this.a = b * 3; 21 System.out.println( "this.a = " + this.a ); 22 System.out.println( "this.b = " + this.b ); 23 System.out.println( "c = " + c ); 24 System.out.println( "b = " + b ); 25 System.out.println( "a = " + a ); 26 System.out.println( "method2() result = " + method2( x + b ) ); 27 System.out.println( "this.a = " + this.a ); 28 System.out.println( "this.b = " + this.b ); 29 30 private int method2( int x ) 31 32 int a = x; 33 int c = this.a + a; 34 b = a!= c; 35 System.out.println( "a = " + a ); 36 System.out.println( "b = " + b ); 37 System.out.println( "c = " + c ); 38 System.out.println( "this.a = " + this.a ); 39 System.out.println( "this.b = " + this.b ); this.a = this.b = 40 this.a = a + 2; 41 this.b = b == false; 42 return x + 3; 43 44 Use the numbers below to identify various program parts. 1) class definition (type) 5) instance method 2) static variable 6) local variable 3) instance variable 7) formal parameter 4) static method 8) constructor Test7 on line 1 a on line 3 b on line 4 x on line 15 main() on line 6 ref on line 8 Test7() on line 11 a on line 17 method1() on line 15 c on line 5 3

8) Given the following if else if sequence below, fill in the blanks to produce an equivalent result with a switch statement. int x = /* some value */; String str; if ( x / 2 == 2 ) str = "2 stars"; else if ( x / 2 == 4 ) str = "4 stars"; else if ( x / 2 == 6 ) str = "6 stars"; else str = "a comet"; System.out.println( str ); switch( ) str = "2 stars"; str = "4 stars"; str = "6 stars"; str = "a comet"; System.out.println( str ); 9) What is the output of this recursive method if it is invoked with the actual argument of 5, as in ref.mystery( 5 );? Draw Stack Frames to help you answer this question. int mystery( int a ) int b = a + 3; if ( b > 5 ) a = mystery( a - 1 ); System.out.println( a + " " + b ); else a = b + 3; System.out.println( a + " " + b ); return b; 4

10) Given the following definitions: public interface Speakable public String speak(); public class Puppy implements Speakable private static final String PUPPY_SPEAK = "Bark"; public Puppy() // ctor initialization here public String speak() return PUPPY_SPEAK; public String wag() return "wag wag"; public class Kitty implements Speakable private static final String KITTY_SPEAK = "Meow"; public Kitty() // ctor initialization here public String speak() return KITTY_SPEAK; public String sleep( int time ) return time + " second cat nap"; And the following variable definitions: private Puppy puppy; private Kitty kitty; private Speakable speakable; Indicate what gets printed with the following statements (each statement is executed in the order it appears). puppy = new Puppy(); kitty = new Kitty(); System.out.println( puppy.speak() ); System.out.println( puppy.wag() ); System.out.println( kitty.speak() ); System.out.println( kitty.sleep( 2000 ) ); speakable = puppy; System.out.println( speakable.getclass().getname() ); System.out.println( speakable.speak() ); speakable = kitty; System.out.println( speakable.getclass().getname() ); System.out.println( speakable.speak() ); What two things would we need to change in Speakable.java, Puppy.java, and/or Kitty.java in order for the statement speakable.sleep( 1000 ); to compile and work properly? Be specific. 1) 2) 5

Scratch Paper 6