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

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

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

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

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

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

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

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

CSE 142 Sample Midterm Exam #2

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

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

CSE142 Sample Midterm, Winter 2018

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

CSE142 Sample Midterm Autumn 2018

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

CSE 142 Sample Midterm Exam #3

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

CSE 142, Spring 2009, Final Exam

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

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

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

CSE 142, Winter 2007 Final Exam. Name:

Sample Midterm Exam #2

CSE 142 Sample Midterm Exam #3

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

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

CSCI 1226 Sample Midterm Exam

CSE 143: Computer Programming II Spring 2015 Final Exam Solutions

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

CSE 143: Computer Programming II Autumn Sample Solutions

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.

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CS 112 Introduction to Programming

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

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

Midterm Review Session

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

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

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

CS141 Programming Assignment #6

CIS Introduction to Computer Programming. 5 October 2012 Midterm

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

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

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

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

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

AP COMPUTER SCIENCE A

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

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

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

Building Java Programs

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

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

Midterm Examination (MTA)

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

This exam is open book. Each question is worth 3 points.

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Building Java Programs

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

Question: Total Points: Score:

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

CS 455 Midterm Exam 1 Spring 2013 [Bono] Feb. 21, 2013

CSE 8A Lecture 21. SMarx extra final exam office hours Fri 3/15 11:15am-1pm EBU-3B #2206

Problem Description Earned Max 1 PHP 25 2 JavaScript / DOM 25 3 Regular Expressions 25 TOTAL Total Points 100. Good luck! You can do it!

CS 177 Spring 2009 Exam I

Building Java Programs

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Introduction to Computer Science Unit 2. Notes

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

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

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

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

1 Short Answer (10 Points Each)

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

Midterm Practice Problems

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

CS 1083 Introduction to Programming I for Computer Scientists Final Solutions

Practice Midterm 1. Problem Points Score TOTAL 50

CONDITIONAL EXECUTION

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

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Control Flow Practice Problems Mr. Fahrenbacher AP Computer Science A

CS 101 Exam 2 Spring Id Name

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Problem Grade Total

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

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

Selection Statements and operators

Name CIS 201 Midterm II: Chapters 1-8

Chapter 4: Control Structures I

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.

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Introduction to Computer Science Unit 2. Notes

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

CIS 110 Fall 2014 Introduction to Computer Programming 8 Oct 2014 Midterm Exam Name:

LAB 4.1 Relational Operators and the if Statement

CS 1331 Exam 1 ANSWER KEY

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

Transcription:

CSE 142, Summer 2010 Midterm Exam, Friday, July 30, 2010 Name: Section: TA: Student ID #: You have 60 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/notes. You may not use any calculators or other computing devices. 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, or for a boolean. Expression 11-7 * 2 + 3 * 4 10 / (5 / 2) + 1.5 * 6 / 2 115 / 10 + 115 % 10 + 11 / 7 * 3.5 "0" + 10 * 5 + "0" + 5 + 6 (4 <= 9 / 2) &&!(2!= 10) 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 scarlett = "mustard"; String suspect = "peacock"; String lounge = "ballroom"; String pipe = "study"; String dagger = "pipe"; String weapon = "dagger"; clue(weapon, suspect, pipe); clue(scarlett, pipe, suspect); clue(dagger, "lounge", scarlett); clue(lounge, dagger, "dagger"); clue(pipe, "miss " + scarlett, lounge); public static void clue(string suspect, String room, String weapon) { System.out.println(room + " in the " + weapon + " with the " + suspect); 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 a, int b) { if (a % 10 == 0) { b *= 10; a += 10; if (a > b) { b = a; else if (a == b) { b++; System.out.println(a + " " + b); Method Call ifelsemystery(20, 8); ifelsemystery(30, 30); ifelsemystery(4, 3); ifelsemystery(30, 4); ifelsemystery(7, 7); 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 whilemystery(int i, int j) { int k = 0; while (i < j && k < j) { i = i + k; j--; k++; System.out.print(i + ", "); System.out.println(k); Method Call whilemystery(3, 5); whilemystery(5, 3); whilemystery(-3, 6); whilemystery(2, 12); whilemystery(-9, 10); 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, never, or sometimes / sometimes. (You may abbreviate them as A, N, or S.) // Reads many integers from Scanner; returns the second smallest // integer read. public static int secondsmallest(scanner console) { int num = console.nextint(); int first = num; int second = num; // Point A while (num >= 0) { // Point B if (num < first) { second = first; first = num; // Point C else if (num < second) { second = num; // Point D num = console.nextint(); // Point E return second; num < 0 first < second num >= second Point A Point B Point C Point D Point E 5 of 8

6. Programming Write a static method speedingticket that decides whether a given driver should be given a speeding ticket from a police officer. The method accepts three parameters: the driver's car speed in miles per hour, as an integer; the current speed limit, as an integer; and whether or not the police officer has eaten a donut today, as a / value. (A police officer that has eaten a donut is happy, so he/she is less likely to give the driver a ticket.) Your method should return if the driver should receive a speeding ticket, and if not. A driver should be given a speeding ticket if any of the following conditions are met: The officer has eaten a donut () and the driver's speed is at least 10 mph over the speeding limit. The officer has not eaten a donut () and the driver's speed is at least 5 mph over or under the limit. The driver is going 100 mph or faster, regardless of the speed limit or donut status. You may assume that the integers passed as parameters will be non-negative. Here are some example calls to the method and their resulting return values: Call speedingticket(58, 55, ) speedingticket(51, 55, ) speedingticket(42, 35, ) speedingticket(30, 35, ) speedingticket(45, 30, ) speedingticket(49, 40, ) speedingticket(22, 30, ) speedingticket(102, 15, ) speedingticket(101, 98, ) Value Returned 6 of 8

7. Programming It is said that all dogs hear when people talk to them are their names (see cartoon by Gary Larson to the right). Write a static method named doghears that prints lines of what a dog hears. The method accepts two parameters: a dog's name, as a string, and the number of lines, as an integer. Each line contains a randomly chosen number of words, between 2-10 words inclusive. Each word on a given line is chosen randomly to be one of two choices: the dog's name, with 25% probability (1/4 likelihood); or the word "blah", with 75% probability (3/4 likelihood). This does not mean that the dogs name will print exactly every fourth time; just that a given word has a 1/4 random chance of being the dog's name. Multiple calls to doghears with the same parameters will likely result in different output for each call. If 0 or less is passed for the number of lines, no output should be produced. The following table lists some calls to doghears: Call doghears("ginger", 7); doghears("kona", 4); Example Output Ginger blah blah blah blah blah blah blah blah blah blah blah blah blah blah Ginger blah blah Ginger blah blah Ginger blah blah blah blah blah blah Ginger blah blah blah blah Ginger blah blah Ginger blah blah blah blah blah blah Ginger blah blah Ginger blah blah blah Kona Kona blah blah blah Kona blah blah Kona blah blah Kona blah 7 of 8

8. Programming Write a method highlow that takes a number, an integer, as a parameter and returns whether or not the number has alternating "high" and "low" digits. 0 through 4 are "low" digits and 5 through 9 are "high" digits. Your method should return if the number passed alternates between "high" and "low" digits, and if not. You may assume the number passed is positive. If the number passed consists of a single digit, highlow should return. Note: highlow returns if the number alternates starting with a "high" digit or starting with a "low" digit. What is important is that the digits alternate. For example, both 9292 and 2929 passed to highlow should return. Here are some example calls to the method and their resulting return values: Call highlow(1918193) highlow(7283) highlow(3827) highlow(9388) highlow(895151) highlow(707) highlow(44) highlow(45) highlow(5) Value Returned 8 of 8