CSE142 Sample Midterm, Winter 2018

Similar documents
CSE142 Sample Midterm Autumn 2018

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

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

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

CSE 142 Sample Midterm Exam #3

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

CSE 142 Sample Midterm Exam #3

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

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

CSE 142 Sample Midterm Exam #2

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

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

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

Building Java Programs

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

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

Building Java Programs

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

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

Question: Total Points: Score:

Midterm Review Session

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

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

CS 112 Introduction to Programming

Midterm Examination (MTA)

CS 101 Spring 2007 Midterm 2 Name: ID:

CMPS 11 Introduction to Programming Midterm 1 Review Problems

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

CS 101 Exam 2 Spring Id Name

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

CIS October 19, 2017

Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution

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

CIS November 14, 2017

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

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

Garfield AP CS. User Input, If/Else. Most slides from Building Java Programs. Thanks, Stuart Regesand Marty Stepp!

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Building Java Programs

AP Computer Science Unit 1. Programs

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

Building Java Programs

CIS October 16, 2018

Arrays. Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals

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

Controls Structure for Repetition

CIS March 1, 2018

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements

assertion: A statement that is either true or false.

Building Java Programs

Name CIS 201 Midterm II: Chapters 1-8

Advanced if/else & Cumulative Sum

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

CS 112 Introduction to Programming

CSE 1223: Exam II Autumn 2016

Name: Checked: Preparation: Response time experiment accessing the system clock

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

Control Flow Practice Problems Mr. Fahrenbacher AP Computer Science A

Introduction to Java Unit 1. Using BlueJ to Write Programs

Building Java Programs

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

Object-oriented Programming and Software Engineering CITS1001. Multiple-choice Mid-semester Test

CS170 (005): Introduction to Computer Science Exam 2

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

CS 1083 Introduction to Programming I for Computer Scientists Sample Final Questions

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

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

Topic 12 more if/else, cumulative algorithms, printf

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

Give one example where you might wish to use a three dimensional array

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

CSE 143 Lecture 10. Recursion

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

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

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

CSE 143 Sample Midterm Exam #1

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

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

CS 305j Midterm 2 Fall 2006

CSE 142, Spring 2009, Final Exam

int x = 42, y = 33; //1 int z = x + y; //2 System.out.println(x + "+" + y + "=" + z); //3

Loops and Expression Types

CS 101 Fall 2006 Midterm 1 Name: ID:

Branching. Chapter 5 11/14/16 & 11/15/16

1 Short Answer (10 Points Each)

CS 367: Introduction to Data Structures Midterm Sample Questions

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

Building Java Programs

St. Edmund Preparatory High School Brooklyn, NY

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

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

Faculty of Science Midterm. COMP-202B - Introduction to Computing I (Winter 2008)

5) (4 points) What is the value of the boolean variable equals after the following statement?

CSE 142 SPRING 2008 FINAL EXAM

CSc 110 Sample Midterm Exam #2

1 Short Answer (15 Points Each)

Transcription:

CSE142 Sample Midterm, Winter 2018 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 constant of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in quotes). Expression Value ---------------------------------------------------------------- 4 * (2 + 4) - 3 * 5.5 _ 6 % 4 + 4 % 6 + 6 % 6 _ 15 / 4 / 3.0-18 / 5 + (15 / 10.0) _ 3 + 3 + "3 * 3" + (3 + 3) * 3 % 3 _ (11!= 7 + 4 3 * 2 <= 39 % 10) == false _ 2. Parameter Mystery, 12 points. Consider the following program. public class Mystery { public static void main(string[] args) { String phone = "app"; String app = "screen"; String screen = "home"; String person = "you"; String me = "person"; call(me, "you", person); call(app, phone, screen); me = "(" + me + ")"; call(me, "me", me); call(screen, phone, app); public static void call(string person, String app, String phone) { System.out.println(app + " calls " + phone + " with " + person); List below the output produced by this program.

3. If/Else Simulation, 12 points. Consider the following method. public static void ifelsemystery(int a, int b) { if (a == b a % 2 == 0) { a = a - b; if (a < b) { a = a + 5; else { b = 10; if (a < b) { b--; a = b + 3; System.out.println(a + " " + b); For each call below, indicate what output is produced. Output Produced ----------------------------------------- ifelsemystery(4, 7); ifelsemystery(5, 5); ifelsemystery(8, 3); ifelsemystery(1, 12); ifelsemystery(9, 6); ifelsemystery(3, 4); 4. While Loop Simulation, 12 points. Consider the following method: public static void mystery(int x) { int y = 0; while (x > 9) { y++; int z = x % 10; x = x / 10 + z; System.out.println(x + " " + y); For each call below, indicate what output is produced. Output Produced --------------------------------------- mystery(6); mystery(34) mystery(721); mystery(65289);

5. Assertions, 15 points. You will identify various assertions as being either always true, never true or sometimes true/sometimes false at various points in program execution. The comments in the method below indicate the points of interest. public static int mystery(int x) { if (x <= 0) { x = 42; int y = 0; // Point A while (x!= 1) { // Point B if (x % 2 == 0) { y++; x = x / 2; // Point C else { x = 3 * x + 1; // Point D // Point E return y; Fill in the table below with the words ALWAYS, NEVER or SOMETIMES. x == 1 x % 2 == 1 y == 0 Point A Point B Point C Point D Point E

6. Programming, 15 points. Write a static method called giveproblems that takes a console scanner and an integer n as parameters and that makes up n multiplication problems for the user to solve. Each multiplication problem involves choosing two numbers that are each between 1 and 12 inclusive. The user should be prompted for the answer and should be told whether their answer was or in. The method should also report the number of problems solved ly and the number of problems given. For example, if the following calls are made: Scanner console = new Scanner(System.in); giveproblems(console, 5); We would expect interaction like the following (user input bold and underlined): 10 * 6 =? 60 9 * 9 =? 82 in...the answer was 81 4 * 10 =? 40 3 * 4 =? 13 in...the answer was 12 8 * 5 =? 40 3 of 5 In this log, the user entered 5 answers (60, 82, 40, 13, 40). All other text was produced as output by the method. Notice that there is a final line of output indicating the overall results. Your method must exactly reproduce the format of this log. Your method should construct a Random object to use for making up random problems. You may assume that the integer passed to your method is greater than 0 and that the user always enters an integer when prompted. 7. Programming, 15 points. Write a static method called printsequenceto that takes a target value as a parameter and that prints terms from a particular numerical sequence until they add up to a value greater than or equal to the target and that returns the number of terms that were included. For example, if the following calls are made: int n1 = printsequenceto(3.0); int n2 = printsequenceto(5.5); The following output should be produced: 1/2 + 2/3 + 3/4 + 4/5 + 5/6 = 3.5500000000000003 1/2 + 2/3 + 3/4 + 4/5 + 5/6 + 6/7 + 7/8 + 8/9 = 6.171031746031746 The variable n1 is set to 5 because it took 5 terms from the sequence to get a sum that is at least 3.0. The variable n2 would be set to 8 because it took 8 terms to get a sum that is at least 5.5. You are to exactly reproduce the format of this output. You may assume that the target is greater than 0. Notice that the sum is not rounded.

8. Programming, 9 points. Write a static method called acronym that takes as a parameter a string containing a phrase and that returns a string that has the acronym for the phrase. For example, the following call: acronym("self contained underwater breathing apparatus") should return "SCUBA". The acronym is formed by combining the capitalized first letters of each word in the phrase. Words in the phrase will be separated by one or more spaces. There might be extra spaces at the beginning or end of the phrase. The string passed as a parameter will not contain any characters other than spaces and letters, and is guaranteed to contain at least one word. Below are several sample calls. Value Returned ----------------------------------------------- -------------- acronym(" automatic teller machine ") "ATM" acronym("personal identification number") "PIN" acronym("computer science") "CS" acronym("merry go round") "MGR" acronym(" All my Children ") "AMC" acronym(" grand old party ") "GOP" acronym(" loner ") "L" You may use only the string methods included on the cheat sheet and you are not allowed to use a scanner to solve this problem.