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

Similar documents
Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Final Exam CS 251, Intermediate Programming December 10, 2014

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Final Exam CS 251, Intermediate Programming December 13, 2017

CS 251, Intermediate Programming Midterm Exam October 9, 2013

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

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

AP CS Unit 4: Classes and Objects Programs

Final Exam. COMP Summer I June 26, points

CS111: PROGRAMMING LANGUAGE II

Key Java Simple Data Types

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

Chapter 4 Defining Classes I

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Java Simple Data Types

Final Exam Practice. Partial credit will be awarded.

COMP 102: Test August, 2017

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects

CS 455 Midterm Exam 1 Fall 2010 [Bono] Sept. 29, 2010

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

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

Introduction to Programming Using Java (98-388)

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

CS 101 Exam 1 Spring 200 Id Name

ITI Introduction to Computing II

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Question: Total Points: Score:

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

This exam is worth 30 points, or about 28% of your total course grade. The exam contains

CS 455 Midterm Exam 1 Fall 2010 [Bono] Sept. 29, 2010

ITI Introduction to Computing II

COMP 102: Test August, 2017

Midterm Exam 2 CS 455, Spring 2015

Prelim 1. Solution. CS 2110, 14 March 2017, 5:30 PM Total Question Name Short answer

CMSC 331 Second Midterm Exam

Computer Science 1 Honors

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

CS 139 Practice Midterm Questions #2

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

Java Simple Data Types

Introduction to Programming (CS112): Sample

1 Inheritance (8 minutes, 9 points)

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

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

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

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

Objects and Classes Lecture 2

Computer Programming, I. Laboratory Manual. Final Exam Solution

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS 251 Intermediate Programming Inheritance

Programming with Java

Exam 1 - (20 points)

1 Method Signatures and Overloading (3 minutes, 2 points)

APCS Semester #1 Final Exam Practice Problems

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CSE351 Winter 2016, Final Examination March 16, 2016

ECE 122. Engineering Problem Solving with Java

CS 113 MIDTERM EXAM 2 SPRING 2013

CS2102, D15 Exam 1. Name:

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

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

Practice Midterm 1. Problem Points Score TOTAL 50

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

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

CS170 Introduction to Computer Science Midterm 2

CS 134 Midterm Fall 2006

Selected Questions from by Nageshwara Rao

CS 101 Spring 2006 Final Exam Name: ID:

CSC 1351 The Twelve Hour Exam From Hell

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

University of Utah School of Computing

A Previous CS 310 Final Exam

Sample Examination Paper Programming and Software Development

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

Gettysburg College Department of Computer Science

CSE wi Midterm Exam 2/8/18. Name UW ID #

CSE 142 Su01 Final Exam Sample Solution page 1 of 7

Static Methods. Why use methods?

CS2102, B11 Exam 1. Name:

Logistics. Final Exam on Friday at 3pm in CHEM 102

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

CS 177 Week 15 Recitation Slides. Review

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

Multiple choice questions. Answer on Scantron Form. 4 points each (100 points) Which is NOT a reasonable conclusion to this sentence:

CSE 142 Su 04 Computer Programming 1 - Java. Objects

CS 2340 Objects and Design - Scala

COS 126 General Computer Science Spring Written Exam 1

Arrays: An array is a data structure that stores a sequence of values of the same type. The data type can be any of Java s primitive types:

Final Exam COMP Fall 2004 Dec 16, 2004

CS 1316 Exam 1 Summer 2009

CMSC 132: Object-Oriented Programming II

Transcription:

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible answers. This is a closed book exam. However, each student is allowed to bring one page of notes to the exam. Print your name at the top of every page. Question: 1 2 3 4 5 6 7 Total Points: 16 12 18 15 12 15 12 100 Score: 1. Select the best type from boolean, double, int, or String to store each of the following. (a) The value of the square root of 2. (a) (b) The number of adults in your household. (b) (c) My middle name. (c) (d) Your height in meters. (d) (e) The result of a coin flip. (e) (f) The title of a book. (f) (g) The current temperature in degrees Celsius. (g) (h) The current state of a light bulb (on or off). (h) 2. Multiple choice questions: Select the single correct answer for each. (a) Which of the following expressions would evaluate to 2.5? A. 5 / 2 B. (int)5.0 / 2 C. (double)(5 / 2) D. (double)5 / 2 (b) Which of the following is not part of all loops? A. initialization B. loop body C. termination condition D. the keyword while Page 1 of 8

(c) The name of the special type of method that creates objects of a class is A. instantiator B. initializer C. creator D. constructor E. declarator (d) Which code would you use to create an array that could hold 50 String objects? A. Strings names = new String(50); B. String names = new String[50]; C. String names[50]; D. String[50] names; E. String[50] names = new String(); F. String[] names = new String; G. String[] names = new String[50]; H. String[] names = new String(50); I. String[] names = new [String](50); (e) What is the value of the following expression? "one" + 2 + 3 * 4 A. "one234" B. "one212" C. "one14" D. 15 E. This expression would result in a compilation error. (f) What is displayed when the following code is compiled and executed? public class StringCompare { String s1 = new String (" Test "); String s2 = new String (" Test "); if (s1 == s2) System. out. println (" Same "); if (s1. equals (s2 )) System. out. println (" Equals "); A. Same Equals B. Equals C. Same D. The code compiles, but nothing is displayed upon execution. E. The code fails to compile. Page 2 of 8

3. Why do the following code snippets not compile? (Explain in one sentence each.) (a) (3) int x; 5 = x; (b) (3) int i = 2; int j = 4; int k = 6; if(i < j < k) { System. out. println (i + " is smallest "); (c) (3) public static String mymethod ( int x) { if( x > 5 ) { return " bigger than five!"; Page 3 of 8

(d) (3) public class Test { public void method () { for ( int i = 0; i < 3; i ++) { System. out. println (i); System. out. println (i); (e) (3) public class MyClass { private int x = 10; System. out. println (x); (f) (3) int [] values = int [ 100]; Page 4 of 8

4. The following Java program compiles and runs. What is its output? (15) public class MethodTest { public static int foo ( int a) { int b = a / 2; int c = b * 3; System. out. println ("a=" + a + ", b=" + b + ", c=" + c); if(c % a == b) return b; else return c; int a = 2; int b = 3; int c = 4; System. out. println (" foo (" + a + ")=" + foo (a )); System. out. println (" foo (" + b + ")=" + foo (b )); System. out. println (" foo (" + c + ")=" + foo (c )); Page 5 of 8

5. The following Java program compiles and runs. What is its output? (12) public class Foo { private int x; public Foo ( int x) { this.x = x; public void printstuff ( int x) { System. out. println (x); System. out. println ( this.x); int x = 5; Foo a = new Foo (x); x += 3; Foo b = new Foo ( x + 1); Foo c = new Foo ( x - 1); a. printstuff (1); b. printstuff ; c. printstuff (3); Page 6 of 8

6. Write a method to return the average of all the positive numbers (numbers greater than zero) (15) in the given array of numbers, returning 0.0 for an array with no positive values. [2, 6, 3, 5] -> 4.0 [2, -1, 8, 5] -> 5.0 [2, -1, -2, 3] -> 2.5 [-2, -1] -> 0.0 [] -> 0.0 public static double averagepositive ( int [] numbers ) { Page 7 of 8

7. The following Java program compiles and runs. What are the first line, third line, and last line (12) of its output? (I don t want all the output, just the lines specified.) public class LoopNest { String [] name = { " John ", " Paul ", " George ", " Ringo " ; String [] adj = {" alive ", " dead ", " young ", " old "; for ( int a =1; a< name. length ; a ++) { for ( int b =0; b<adj. length ; b ++) { for ( int c =3; c <5; c ++) { String str = name [a] + " is " + adj [b] + ", " + c; System. out. println ( str ); Page 8 of 8