CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 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, Summer 2010 Midterm Exam, Friday, July 30, 2010

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

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

CSE142 Sample Midterm Autumn 2018

CSE142 Sample Midterm, Winter 2018

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

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

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

CSE 142 Sample Midterm Exam #3

CSE 142 Sample Midterm Exam #3

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

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

CSE 142 Sample Midterm Exam #2

CSE 142, Spring 2009, Final Exam

Midterm Review Session

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

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

CSE 142, Winter 2007 Final Exam. Name:

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

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

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

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

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

Sample Midterm Exam #2

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

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

CS 112 Introduction to Programming

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSE 143: Computer Programming II Autumn Sample Solutions

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

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

CSE 143: Computer Programming II Spring 2015 Final Exam Solutions

Midterm Examination (MTA)

CSCI 1226 Sample Midterm Exam

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

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

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

Controls Structure for Repetition

Repetition, Looping. While Loop

Question: Total Points: Score:

1 Short Answer (10 Points Each)

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

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

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

Building Java Programs

CMP 326 Midterm Fall 2015

CSIS-120 Final Exam Fall 2015 Name:

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

Building Java Programs

CS 101 Spring 2007 Midterm 2 Name: ID:

CSE 1223: Exam II Autumn 2016

AP COMPUTER SCIENCE A

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

CMPS 11 Introduction to Programming Midterm 1 Review Problems

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

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

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

Object Oriented Programming. Java-Lecture 1

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

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

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

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

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

COMP-202 Unit 4: Programming with Iterations

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

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

CIS November 14, 2017

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

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

Building Java Programs

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

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

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

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

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

CS 305j Midterm 2 Fall 2006

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

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

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

University of Massachusetts Amherst, Electrical and Computer Engineering

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

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops

Name CIS 201 Midterm II: Chapters 1-8

CIS Introduction to Computer Programming. 5 October 2012 Midterm

COE 212 Engineering Programming. Welcome to Exam I Thursday June 21, Instructor: Dr. Wissam F. Fawaz

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them.

Loops. Repeat after me

Problem Grade Total

CSIS-120 Final Exam Fall 2015 Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

Building Java Programs

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

CS 101 Exam 2 Spring Id Name

CS 312 Midterm 1 Spring 2013

Building Java Programs

Assignment 2.4: Loops

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

Transcription:

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010 Name: Section: TA: Student ID #: 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/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 9

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 12 / 3 + 5 + 3 * -2 1 + 1 + "(1 + 1)" + 1 + 1 13 / 2-38 / 5 / 2.0 + (15 / 10.0) 11 < 3 + 4!(5 / 2 == 2) 20 % 6 + 6 % 20 + 6 % 6 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) { int a = 5; int b = 1; int c = 3; int three = a; int one = b + 1; axiom(a, b, c); axiom(c, three, 10); axiom(b + c, one + three, a + one); a++; b = 0; axiom(three, 2, one); public static void axiom(int c, int b, int a) { System.out.println(a + " + " + c + " = " + b); 2 of 9

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) { if (x == y) { x = x + 11; else if (x > 2 * y) { x = 0; if (x == 0 y > x) { x = x + 2; y = y + 2; System.out.println(x + " " + y); Method Call ifelsemystery(5, 5); ifelsemystery(18, 4); ifelsemystery(3, 6); Output 3 of 9

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 x, int y) { while (x > 0 && y > 0) { x = x - y; y--; System.out.print(x + " "); System.out.println(y); Method Call whilemystery(7, 5); whilemystery(20, 4); whilemystery(40, 10); Output 4 of 9

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. (You may abbreviate them as A, N, or S.) public static int stuff(random r, int m) { int c = 0; int t = 0; int d = r.nextint(m); // Point A while (c <= 3) { // Point B d = r.nextint(6) + 1; if (d <= m) { c++; // Point C else { c = 0; // Point D t++; // Point E return t; c > 3 d <= m c == 0 Point A Point B Point C Point D Point E 5 of 9

6. Programming Write a static method named xo that accepts an integer size as a parameter and prints a square of size by size characters, where all characters are "o" except that an "x" pattern of "x" characters has been drawn from the corners of the square. In other words, on the first line, the first and last characters are "x"; on the second line, the second and second-from-last characters are "x"; and so on. If 0 or less is passed for the size, no output should be produced. The following table lists some calls to your method and their expected output: Call xo(5); xo(8); xo(3); xo(1); xo(0); xo(12); xo(11); Example Output xooox oxoxo ooxoo oxoxo xooox xoooooox oxooooxo ooxooxoo oooxxooo oooxxooo ooxooxoo oxooooxo xoooooox xox oxo xox x xoooooooooox oxooooooooxo ooxooooooxoo oooxooooxooo ooooxooxoooo oooooxxooooo oooooxxooooo ooooxooxoooo oooxooooxooo ooxooooooxoo oxooooooooxo xoooooooooox xooooooooox oxoooooooxo ooxoooooxoo oooxoooxooo ooooxoxoooo oooooxooooo ooooxoxoooo oooxoooxooo ooxoooooxoo oxoooooooxo xooooooooox 6 of 9

7. Programming Write a static method named anglepairs that accepts three angles (integers), measured in degrees, as parameters and returns whether or not there exists both complementary and supplementary angles amongst the three angles passed. Two angles are complementary if their sum is exactly 90 degrees; two angles are supplementary if their sum is exactly 180 degrees. Therefore, the method should return true if any two of the three angles add up to 90 degrees and also any two of the three angles add up to 180 degrees; otherwise the method should return false. You may assume that each angle passed is non-negative. Here are some example calls to the method and their resulting return values. Call anglepairs(0, 90, 180) anglepairs(45, 135, 45) anglepairs(177, 87, 3) anglepairs(120, 60, 30) anglepairs(35, 60, 30) anglepairs(120, 60, 45) anglepairs(45, 90, 45) anglepairs(180, 45, 45) Value Returned true true true true false false false false 7 of 9

8. Programming Write a static method named baseball that takes a Scanner representing the console as a parameter and plays an interactive baseball scoring game with the user, returning an integer representing which team won the game. Baseball is a sport where teams play a series of innings against each other. Each team scores a certain number of runs (points) in each inning. A baseball game ends when one of the following conditions is met: After 9 innings are finished, if one team has more total runs than the other, the team with more runs wins. After 9 innings are finished, if the teams are tied (if they have the same number of total runs), we keep playing one more full inning at a time until the teams are not tied any more. After any inning, if one team is ahead by 10 or more runs, the game is called and the team with more runs wins. Your method should repeatedly prompt the user, once per inning, to enter the number of runs that each team scored during each inning. The user will type in the first team's runs for that inning, followed by the second team's runs for that inning, separated by whitespace. Your method should stop prompting once one or more of the above bulleted conditions are met, causing the game to end. At the end of the game, you should print the final score. You should also return an integer for which team won: return 1 if the first team won, and 2 if the second team won. You may assume that the user enters valid non-negative integers whenever prompted, and you may assume that the game will eventually end (it won't go on forever). Here are some example calls to the method and their resulting output and return values: Scanner console = new Scanner(System.in); Call // typical game // 10 run limit; game called // extra innings baseball(console); baseball(console); baseball(console); Example Inning #1: 1 1 Inning #1: 0 1 Inning #1: 0 1 Inning #2: 0 0 Inning #2: 1 2 Inning #2: 1 0 Output Inning #3: 2 1 Inning #3: 0 3 Inning #3: 0 3 Inning #4: 0 2 Inning #5: 1 0 Inning #6: 1 1 Inning #7: 3 1 Inning #8: 0 0 Inning #9: 1 0 Final score: 9-6 Inning #4: 1 1 Inning #5: 0 4 Inning #6: 1 2 Final score: 3-13 Inning #4: 1 0 Inning #5: 2 0 Inning #6: 1 2 Inning #7: 1 0 Inning #8: 0 0 Inning #9: 1 1 Inning #10: 0 0 Inning #11: 0 1 Final score: 7-8 Returns 1 2 2 (More writing space can be found on the next page.) 8 of 9

8. Programming (writing space) 9 of 9