CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

Similar documents
CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

CSE 142, Summer 2010 Midterm Exam, Friday, July 30, 2010

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

CSE 142 Sample Midterm Exam #2

Building Java Programs A Back to Basics Approach 4th Edition Reges TEST BANK Full download at:

1. An operation in which an overall value is computed incrementally, often using a loop.

CSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA

CSE 142 Sample Midterm Exam #3

CSE 142, Autumn 2010 Final Exam Wednesday, December 15, Name:

CSE142 Sample Midterm Autumn 2018

NoSuchElementException 5. Name of the Exception that occurs when you try to read past the end of the input data in a file.

Sample Midterm Exam #2

CSE142 Sample Midterm, Winter 2018

CSE142 Midterm Autumn This exam is divided into eight questions with the following points: # Problem Area Points Score

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

CSE 142 Sample Midterm Exam #3

CSE 142, Spring 2009, Final Exam

CSE 142, Spring 2010 Final Exam Wednesday, June 9, Name: Student ID #: Rules:

CIS 110 Introduction To Computer Programming. November 21st, 2011 Exam 2

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CSE 143: Computer Programming II Autumn Sample Solutions

CSE 143, Winter 2010 Final Exam Thursday, March 18, 2010

CSE 143, Winter 2009 Final Exam Thursday, March 19, 2009

CSE 142, Winter 2007 Final Exam. Name:

Midterm Review Session

Name CIS 201 Midterm II: Chapters 1-8

CSE 143: Computer Programming II Spring 2015 Final Exam Solutions

Some Practice Midterm Problems

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

CS 112 Introduction to Programming

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

Problem Description Earned Max 1 CSS 20 2 PHP 20 3 SQL 10 TOTAL Total Points 50

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key for review problems

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Review problems

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key

CSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number:

CIS Introduction to Computer Programming. 5 October 2012 Midterm

Building Java Programs

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

Building Java Programs

Building Java Programs

CSCI 1226 Sample Midterm Exam

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

CS141 Programming Assignment #6

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Building Java Programs

CSE 142 Sample Final Exam #2

CIS 110 Introduction to Computer Programming Summer 2014 Midterm. Name:

CONDITIONAL EXECUTION

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

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

assertion: A statement that is either true or false.

CS 305j Midterm 2 Fall 2006

Control Flow Practice Problems Mr. Fahrenbacher AP Computer Science A

COS 126 Midterm 1 Written Exam, Fall 2009

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

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

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

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Building Java Programs Sample Final Exam #1. Name of Student. Section (e.g., AA)

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

CSE 154, Autumn 2012 Final Exam, Thursday, December 13, 2012

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam

Problem Description Earned Max 1 HTML / CSS Tracing 20 2 CSS 20 3 PHP 20 4 JS / Ajax / JSON 20 5 SQL 20 X Extra Credit 1 TOTAL Total Points 100

Problem Points Score Grader Total 75

Practice Midterm 1. Problem Points Score TOTAL 50

I. True/False: (2 points each)

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

CSE 142 Sample Final Exam #2 (based on Autumn 2007's final)

Building Java Programs

Computer Programming, I. Laboratory Manual. Final Exam Solution

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

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

CIS 110 Introduction To Computer Programming. December 19th, 2011 Final. Answer key

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

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

Building Java Programs

CSE 373, Winter 2013 Final Exam, Tuesday, March 19, Good luck! You can do it!

1 Short Answer (10 Points Each)

Practice Midterm 1 Answer Key

Repetition, Looping. While Loop

CSE 1223: Exam II Autumn 2016

Problem Description Earned Max 1 HTML / CSS Tracing 20 2 CSS 20 3 PHP 20 4 JS / Ajax / JSON 20 5 SQL 20 X Extra Credit 1 TOTAL Total Points 100

CIS November 14, 2017

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

CONDITIONAL EXECUTION

Question: Total Points: Score:

CS 1083 Introduction to Programming I for Computer Scientists Final Solutions

CIS 110 Introduction To Computer Programming. December 19th, 2011 Final. Answer key for review problems

Transcription:

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011 Name: Section: Student ID #: TA: You have 50 minutes to complete this exam. You may receive a deduction if you keep working after the instructor calls for papers. This exam is open-book. You may not use any computing devices including calculators. Code will be graded on proper behavior/output and not on style, unless otherwise indicated. Do not abbreviate code, such as "ditto" marks or dot-dot-dot... marks. The only abbreviations that are allowed for this exam are: S.o.p for System.out.print, S.o.pln for System.out.println, and S.o.pf for System.out.printf. You do not need to write import statements in your code. If you enter the room, you must turn in an exam before leaving the room. You must show your Student ID to a TA or instructor for your exam to be accepted. Good luck! Score summary: (for grader only) Problem Description Earned Max 1 Expressions 10 2 Parameter Mystery 15 3 If/Else Simulation 10 4 While Loop Simulation 10 5 Assertions 15 6 Programming 15 7 Programming 15 8 Programming 10 TOTAL Total Points 100 1 of 8

1. Expressions For each expression at left, indicate its value in the right column. List a value of appropriate type and capitalization. e.g., 7 for an int, 7.0 for a double, "hello" for a String, true or false for a boolean. Expression 5 + 2 * 4 / 3 + 5 5 + 5 + "23.0" + 5 + 2 * 5!(5 > 2 && -2 > 2) 5 / 2 == 0 15 % 9 % 4 + 4 % 6 % 3 12 / 5 / 2.0 + 2 * 4 Value 2. Parameter Mystery At the bottom of the page, write the output produced by the following program, as it would appear on the console. public class ParameterMystery { public static void main(string[] args) { String bril = "vorpal"; String gyre = "jubjub"; String slithy = "snack"; String tum = "mut"; String mut = tum + 1; mystery(bril, slithy, gyre); mystery(gyre, "gyre", mut); mystery(gyre + slithy, bril, tum); tum = "tumtum"; bril = "slithy"; mystery(tum, gyre, slithy); public static void mystery(string gyre, String bril, String slithy) { System.out.println("Twas " + bril + " and the " + slithy + " toves did " + gyre); 2 of 8

3. If/Else Simulation For each call below to the following method, write the output that is produced, as it would appear on the console: public static void ifelsemystery(int x, int y) { int z = 0; if (x >= y) { x = x / 2; z++; if (x > z && y <= z) { z++; else if (x > z) { y = y - 5; System.out.println(x + " " + y + " " + z); Method Call ifelsemystery(4, 1); ifelsemystery(-10, 100); ifelsemystery(18, 4); ifelsemystery(-12, 5); Output 3 of 8

4. While Loop Simulation For each call below to the following method, write the output that is produced, as it would appear on the console: public static void mystery(int x, int y) { int z = 1; while (x > 0) { System.out.print(y + ", "); y = y - z; z = z + y; x--; System.out.println(y); Method Call mystery(2, 3); mystery(3, 5); mystery(4, 7); Output 4 of 8

5. Assertions For each of the five points labeled by comments, identify each of the assertions in the table below as either being always true, never true, or sometimes true / sometimes false. public static int mystery(scanner console, int f) { int num = console.nextint(); int h = 0; // Point A while (f < 5) { // Point B if (num == 0) { h = 0; f++; // Point C else { // Point D h++; num = console.nextint(); // Point E return f; Fill in each box below with one of ALWAYS, NEVER or SOMETIMES. (You may abbreviate them as A, N, or S.) h == 0 f >= 5 num == 0 Point A Point B Point C Point D Point E 5 of 8

6. Programming Write a static method named twoconsecutive that accepts three integers as parameters and returns true if there is at least one pair of integers that differ by exactly 1. For example, the integers 3 and 4 differ by 1. The integers 12 and 11 also differ by 1. Your method should return false if there are no such consecutive values. The integers could be passed in any order; the two consecutive values could be any of the two values passed in. Here are some sample calls: Call twoconsecutive(1, 2, 12) twoconsecutive(1, 12, 2) twoconsecutive(2, 12, 1) twoconsecutive(4, 5, 3) twoconsecutive(2, 4, 6) twoconsecutive(8, 8, 8) Output true true true true false false 6 of 8

7. Programming Write a static method named stitching that accepts two integer parameters w and h and that prints a rectangle of dashes and numbers. Each of the h lines printed will contain w integers separated by dashes. The first number on each line is the line number. For example, the first line s first number is 1 and the sixth line s first number is 6. The lines alternate between starting with a dash and ending with a dash. For example, the first, third and fifth lines start with a dash and the second, fourth and sixth lines start with a number. You may assume that the value of each parameter is greater than or equal to 1. Your output must exactly match the format shown. Here are some example calls to the method and their resulting console output: Call stitching(6, 2); stitching(2, 3); stitching(2, 6); stitching(1, 1); Output -1-2-3-4-5-6 -1 2-3-4-5-6-7- -1-2 2-3- -3-4 -1-2 2-3- -3-4 4-5- -5-6 6-7- 7 of 8

8. Programming Write a static method named sameflip that accepts a Random object as a parameter. Your method should flip a coin until the same result occurs twice in a row. In other words, if a head is flipped followed by another head or if a tail is flipped followed by another tail, your method should end. You should use the Random object to give an equal chance to a head or tail appearing. Each time the coin is flipped, print H for heads or T for tails. For example, if the following variable is initialized: Random r = new Random(); Here are some sample calls along with possible output: Call sameflip(r); sameflip(r); sameflip(r); sameflip(r); Output HTHH HTHTT TT THTHTHH 8 of 8