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

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

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

CSE142 Sample Midterm, Winter 2018

CSE 142 Sample Midterm Exam #2

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

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

CSE142 Sample Midterm Autumn 2018

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 2007 Midterm Exam, Friday, November 2, 2007

CSE 142 Sample Midterm Exam #3

Sample Midterm Exam #2

CSE 142 Sample Midterm Exam #3

Building Java Programs

CSE 142, Spring 2009, Final Exam

Building Java Programs

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

Building Java Programs

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

CS 305j Midterm 2 Fall 2006

Question: Total Points: Score:

CSE143 Summer 2008 Final Exam Part B KEY August 22, 2008

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

CSE 1223: Exam II Autumn 2016

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

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

CSE143 Summer 2008 Final Exam Part A KEY August 21, 2008

Place your name tag here

Midterm Review Session

assertion: A statement that is either true or false.

CSE 142, Winter 2007 Final Exam. Name:

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

CS 101 Spring 2007 Midterm 2 Name: ID:

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

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

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

CIS Introduction to Computer Programming. 5 October 2012 Midterm

Type boolean. Building Java Programs. Recap: Type boolean. "Short-circuit" evaluation. De Morgan's Law. Boolean practice questions.

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

1. Reference Mystery, 5 points. What output is produced by this program? import java.util.*;

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

CS 112 Introduction to Programming

(the bubble footer is automatically inserted into this space)

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

University of Massachusetts Amherst, Electrical and Computer Engineering

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

CSE 143 Lecture 10. Recursion

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

CSE 143 Sample Midterm Exam #1

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

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

Building Java Programs

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

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

Computer Security Spring 2010 Paxson/Wagner HW 4. Due Thursday April 15, 5:00pm

Building Java Programs

CIS November 14, 2017

CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Session 14 March 31, 2018

Instructor: Yu Wang 11/16/2012

New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case. Instructions:

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

CS 101 Exam 2 Spring Id Name

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Final. Your Name CS Fall 2014 December 13, points total Your Instructor and Section

Control Flow Practice Problems Mr. Fahrenbacher AP Computer Science A

CSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:

CS 312 Exam 2 Fall Circle your TA's Name: Aish Anthony Bri Carla Chris

CS 367: Introduction to Data Structures Midterm Sample Questions

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Back to Basics for APCS Success

Assignment 2.4: Loops

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

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

STUDENT LESSON A12 Iterations

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

CS 112 Introduction to Programming

Flow of Control of Program Statements CS 112 Introduction to Programming. Basic if Conditional Statement Basic Test: Relational Operators

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

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

CS 177 Spring 2009 Exam I

Project#3 [40 points] COP 2220 Fall 2017

Final Exam Practice. Partial credit will be awarded.

CIS November 14, 2017

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

Problem Grade Total

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

Question: Total Points: Score:

CIS 110 Introduction to Computer Programming Fall 2017 Midterm. Recitation ROOM :

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

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

Transcription:

CSE142 Midterm Autumn 2015 This exam is divided into eight questions with the following points: # Problem Area Points Score 1 Expressions 10 og 2 Parameter Mystery 12 f/else Simulation 12 \1^ \1^ 4 While Loop Simulation 12 5 Assertions 15 i-u 6 Programming 15 1 7 Programming 15 8 Programming 9 H Total 100 This is a closed-book/closed-note exam. Space is provided for your answers. There is a "cheat sheet" at the end that you can use as scratch paper or to write answers. You can also request scratch paper from a TA. You are not allowed to access any of your own papers during the exam. The exam is not graded on style and you do not need to include comments, although you are limited to the constructs included in chapters 1 throuqh 5 of the textbook. You are allowed to abbreviate "Always", "Never," and "Sometimes" as "A", "N", and "S" for the assertions question, but you should otherwise NOT use any abbreviations on the exam. You are NOT to use any electronic devices while taking the test, including calculators. Anyone caught using an electronic device will receive a 10 point penalty. Do not begin work on this exam until instructed to do so. Any student who starts early or who continues to work after time is called will receive a 10 point penalty. f you finish the exam early, please hand your exam to the instructor and exit quietly.

1. Expressions, 10 points. For each expression in the left-hand column, indicate its value in' the right-hand column. Be sure to list a consta appropriate type (e.g., 7.0 rather than 7 for a double. Strings in quot Expression 1 2 * 5 / v a.5 2.5*2*5/ 101.5 85--%^ 4-%-±0 - -17-^-^..2--K- (^ K-4.) -2-^^ 482-7^<Lj / 5/ 2.0*2 14/5 16 Value 4,0 i( t( s,76 [ (.0 <1 ^ 0 -j ^ 2. Parameter Mystery, 12 points. Consider the following program. public class Mystery { public static void main(strihg[] args) { String she = "it"; String it = "her"; String her = "you"; String yoo_5_ lija^; saying(yoh^ i^, you); saying(it, her, she); saying(she, "you", her); saying(it, "him", "fred"); public static void saying(string it. String her. String she) { System.out.println(she " can't take " it " with " her); List below the output produced by this program. <yf\ -V hike '^(Xj C<5ti'4 h \A!\^h ycu {^(5^ co/im ^(\ki \f\^ 1^1 n)

Simulation, 12 points. Consider the following method public static void ifelsemystery(int a, int b) { if (a < b) { a = a 2; tj b,= b - ; U. else if (a == b) { a = a * 2; O b = b 5; else { O a = a - ; 5 > if (a == b) { b = b 10; System.out.println(a " " b); For each call below, indicate what output is produced. Method Call ifelsemystery(2, 5) ifelsemystery(5, 5) ifelsemystery(6, ) ifelsemystery(4, 4) ifelsemystery(, 8) ifelsemystery(9, 5) Output Produced g 10 20 4. While Loop Simulation, 12 points. Consider the following method: 5 G 5 public static void mystery(int x) { int y = 1; int z = while (x > z) { if (x % z == 0) { X = X- / z; y; else { Z; System.out.println(y " z); For each call below, indicate what output is produced: Method Call mystery(2); mystery(5); mysteryj^; ^ mystery(12); Output Produced a -2. g a 1 -z a 6 5 5 15 Y

5. Assertions, 15 points. You will identify various assertions as bein always true, never true or sometimes true/sometimes false at various in program execution. The comments in the method below indicate the of interest. lah public static void mystery(scanner console) { int y = 42; int z = 0; // Point A while (y!= 0) { ^^ ^ // Point B y = console.nextint0; if (y % 2 == 0) { Z; // Point C wc /)d<^ // Point D Od 0^^ o y--; // Point E System.out.printlnC'z = z); A A, ro 0/^ '0 P po Fill in the table below with the words ALWAYS, NEVER or SOMETMES. Point Point Point Point Point A B C D E y == 0 y % 2 == 0 z == 0 K/ \ f\ \...... i...i....^a...1......rsl...i- '.. y......i- --S...

L u 0 ' 'j ^ points. Write a. static method called spinwheel that takes a id an'integer n as parameters and that simulates the spinning the number 20 comes up n times in a row. On the wheel are 0, 40, 50, and 60 and each number should be equally likely the wheel is spun. Your method should report the individual 5 indicating how many times it takes to get n occurrences of Dr example, below are two sample calls: = new Random 0; Mr, 2); Mr, ); should produce two lines of output like this: 40, 50, 20, 50, 50, 40, 20, 0, 40, 50, 20, 20 after 1 spins should produce two lines of output like this: 50, 50, 20, 40, 20, 40, 20, 20, 20 after 10 spins spin values ape separated by commas and that the method las seen n occurrences of the value 20 in a row. You are to ice the format of these logs. You may assume that the value n method is greater than or equal to 1. void ^ non p /fii O' 5 piw;; > rn 0 y P<(\^j C6^K\\ ;, (c J ^ J f 2)$ i-f- Covm \ \ J 4-2)^/0 a H 6 Covn-^ 0\ ' / V Sy5 (fna,(vi"'pr''l4lri -t

ng, 15 points. Write a static method called spinwheel that takes a,m object and an integer n as parameters and that simulates the spinning f' a wheel until the number 20 comes up n times in a row. On the wheel are the numbers 20, 0, 40, 50, and 60 and each number should be equally likely to come up when the wheel is spun. Your method should report the individual spins as well as indicating how many times it takes to get n occurrences of 20 in a row. For example, below are two sample calls: c * ' S' ^ ^ Random r = new RandomO; spinwheel(r, 2); spinwheel(r, ); P P The first call should produce two lines of output like this: spins: 40, 40, 50, 20, 50, 50, 40, 20, 0, 40, 50, 20, 20 2 in a row after 1 spins The second call should produce two lines of output like this: spins: 50, 50, 50, 20, 40, 20, 40, 20, 20, 20 in a row after 10 spins Notice that the spin values are separated by commas and that the method stops when it has seen n occurrences of the value 20 in a row. You are to exactly reproduce the format of these logs. You may assume that the value n passed to your method is greater than or equal to 1. 1a pri^viws^j/ J T "5 W '^S i/^hi (c s>.'^a1^.' ( f 2)^ Covm ) 2))elD a H 1 N S 'C 0VV''' O' <r ^ u ^ r^p'iwsft; f nvwac);^'^' Svsfew.(vTiPrHn [r(aa\ gpivs sj iav-s 0/ ^

Programming, 15 points. Write a static method called balancecheckbd takes a console Scanner as a parameter and that prompts a user for information about transactions for a bank account, reporting the new b after each transaction and the minimum balance at the end and returning whether or not the account was ever overdrawn (true if it was, false if i was not). The user is prompted for an initial balance, the number of transactions to process, and the individual transaction amounts. Deposits to the account are entered as positive numbers and checks and ATM withdrawals are entered as negative numbers. A new balance is reported after each transaction. For example, the method would be called as follows: Scanner console = new Scanner(System.in); balancecheckbook(console); Below are two sample logs of execution that might be produced: initial balance? 48.50 how many transactions? 4 1/4 amount? -20.00 new balance = $28.5 2/4 amount? -5.75 new balance = $22.75 /4 amount? 18.20 new balance = $160.95 4/4 amount? -20.00 new balance = $140.95 minimum balance = $22.75 initial balance? 9.75 how many transactions? 5 1/5 amount? -18.50 new balance = $21.25 2/5 amount? -7.20 new balance = $14.05 /5 amount? -2.10 new balance = $-9.05 4/5 amount? 50.00 new balance = $40.95 5/5 amount? -8.45 new balance = $2.5 minimum balance = $-9.05 n the log to the left, the user enters 4 different transactions and the minimum balance is not negative, so the method would return false to indicate that the account was never overdrawn. n the log to the right, the user enters 5 transactions and the minimum balance is negative, so the method would return true to indicate that the account was overdrawn. You are to exactly reproduce the format of these logs. You may assume that the number of transactions entered by the user is at least 1. Space is provided on the opposite page for your answer.

y.. provide your answer to balancecheckbook below. r ys<rn.aaf)i'f)^'ir),-l,'^( Marcel j>\ VJ np^- Aojiole ohn - ^ ''-y fisi' Cm ^ JL' ' i tt'- JU -^/ ' <-n M _ ^(mv t'l ;,s - '«n fr\m - d ''i ( i {!-r\ t V

8, or- Programming, 9 points. Write a static method called samedashes th two strings as parameters and that returns whether or not they have d in the same places (returning true if they do and returning false otherwise). For example, below are four pairs of strings of equal lengt that have the same pattern of dashes. Notice that the last pair has no dashes at all. Stringl: stringz: "hi--there-you." "12--(14)-759" "-15-89" -xy-zzy "criminal-plan" "(206)555-184" "ab,c" "9.8" To be considered a match, the strings must have exactly the same number of dashes in exactly the same positions. The strings might be of different length. For example, the following calls should each return true: samedashes("lst-has-more characters", "2nd-has-less") samedashes("lst-has-less", "2nd-has-more characters") because the strings each have two dashes and they are in the same positions. But the following calls should each return false because the longer string has a third dash where the shorter string does not: samedashes("1st-has-more-characters", "2nd-has-less") samedashes("1st-has-less", "2nd-has-more-characters") n solving this problem you may use only methods listed ui L 1C Cl ica L 'a s4.ica»t,ri ^ Y-= i,, 1-0/i ^ X' i)5( si. r,

C\jr^