Midterm Exam 2 Thursday, November 15th, points (15% of final grade) Instructors: Jim Williams and Marc Renault

Similar documents
Computer Science 300 Sample Exam Today s Date 100 points (XX% of final grade) Instructor Name(s) (Family) Last Name: (Given) First Name:

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination

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

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

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

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

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

Index COPYRIGHTED MATERIAL

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination

Using Java Classes Fall 2018 Margaret Reid-Miller

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

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Welcome to the Using Objects lab!

Faculty of Science COMP-202B - Foundations of Computing (Winter 2016) - All Sections Midterm Examination

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

Full file at

COMP102: Test. 26 April, 2006

Operators. Java operators are classified into three categories:

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2010) - All Sections Final Examination

A variable is a name for a location in memory A variable must be declared

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

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

"Hello" " This " + "is String " + "concatenation"

TeenCoder : Java Programming (ISBN )

Primitive Data Types: Intro

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

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

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

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

ECE 122 Engineering Problem Solving with Java

A token is a sequence of characters not including any whitespace.

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

Data Conversion & Scanner Class

Faculty of Science COMP-202B - Foundations of Computing (Winter 2016) - All Sections Final Examination

Programming II (CS300)

CS 367: Introduction to Data Structures Midterm Sample Questions

CompuScholar, Inc. 9th - 12th grades

COMP Primitive and Class Types. Yi Hong May 14, 2015

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2011) - All Sections Midterm Examination

Basic Computation. Chapter 2

Computer Science 145

AP Computer Science A

Computer Science 145 Midterm 1 Fall 2016

CMSC 206: Data Structures Final Exam Reference May 2018

We now start exploring some key elements of the Java programming language and ways of performing I/O

Programming with Java

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

Pace University. Fundamental Concepts of CS121 1

Basic Computation. Chapter 2

Elementary Programming

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

CSE 143 Lecture 4. ArrayList. Reading: slides created by Marty Stepp

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

Repetition. Chapter 6

Repetition. Chapter 6

Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

CSE 373. Data Types and Manipulation; Arrays. slides created by Marty Stepp

Lecture 8: The String Class and Boolean Zen

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

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

JAVA OPERATORS GENERAL

Chapter 2: Data and Expressions

CS 302: Introduction to Programming

Mr. Monroe s Guide to Mastering Java Syntax

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Operators in java Operator operands.

Week 6: Review. Java is Case Sensitive

Chapter 2: Data and Expressions

Midterm Review 01. SP17 ICS 111 Ed Meyer

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

CS 106 Introduction to Computer Science I

CSE 143 Au03 Midterm 2 Page 1 of 7

CS 307 Final Spring 2008

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

CS Introduction to Data Structures Week 1 Thursday

JVM (java) compiler. A Java program is either a library of static methods (functions) or a data type definition

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Object-Oriented Programming

What did we talk about last time? Examples switch statements

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

Adam Blank Lecture 2 Winter 2019 CS 2. Introduction to Programming Methods

Section 2: Introduction to Java. Historical note

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

H212 Introduction to Software Systems Honors

QUIZ: What value is stored in a after this

CS 106 Introduction to Computer Science I

CIS 110: Introduction to Computer Programming

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

CSC 1214: Object-Oriented Programming

CS Programming I: Branches

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Lab 14 & 15: String Handling

Transcription:

Computer Sciences 200 Midterm Exam 2 Thursday, November 15th, 2018 100 points (15% of final grade) Instructors: Jim Williams and Marc Renault (Family) Last Name: (Given) First Name: CS Login Name: NetID (email): @wisc.edu Circle your Lecture: Lec001 TR 0800 (Jim) Lec002 TR 0930 (Jim) Lec003 MWF 1100 (Marc) Lec004 MWF 1320 (Marc) Fill in these fields (left to right) on the scantron form using a #2 pencil. 1. LAST NAME (family name) and FIRST NAME (given name), as much as there is space to enter. 2. IDENTIFICATION NUMBER is your Campus ID number. 3. SPECIAL CODES ABC: Enter your three-digit lecture number: 001, 002, 003, or 004. 4. SPECIAL CODES F: Write the letter P for Primary and fill in the bubble for (1). FILL IN THE BUBBLES CORRESPONDING TO ALL OF THESE ANSWERS! The exam has two parts and is worth a total of 100 points. Part I has 20 Simple Choice questions worth 2 points each for 40 points possible for Part I. Part II has 20 Multiple Choice questions worth 3 points each for 60 points possible for Part II. You will have 120 minutes to complete the exam. Be sure to read through every question completely. I certify that I will keep my answers covered so that they may not be viewed by another student during the exam or prior to completion of their exam. I also certify that I will not view or in any way use another s work or any unauthorized devices. I understand that I may not make any type of copy of any portion of this exam without express permission from my instructor. I understand that being caught allowing another to view my work or being caught viewing another s work are both violations of this agreement and either may result in automatic failure of the course. Any penalty may also be reported to the Deans Office for all involved. Signature: 1. Be sure to review the reference pages as needed during the exam. 2. Turn off and put away your cell phone, calculator, Inspector Gadget (watches, glasses, pencils, etc.) now and wait for the proctor to signal the start of the exam. c 2018 Williams, Renault CS200 Midterm Exam 2 (P) Page 1 of 7

Disclaimer: the following are provided for your reference only, and the inclusion of information here does not guarantee it will be used on the exam. Operator Precedence Table: Level Operator Description Associativity higher ( <expression> ) grouping with parentheses left to right [ ] ( ). array index, method call, member access (dot operator) left to right ++ -- post-increment, post-decrement left to right ++ -- + -! pre-increment, unary plus/minus, logical negation right to left (type) new casting and creating object right to left * / % multiplication, division, modulus left to right + - + addition, subtraction, concatenation left to right < <= > >= instanceof relational and Java s instanceof operator left to right ==!= equality left to right && conditional AND (short-circuits) left to right conditional OR (short-circuits) left to right lower? : ternary conditional right to left = += -= *= /= %= assignment, arithmetic (compound) assignment right to left Methods from the java.lang.string class: int length() char charat(int index) boolean contains(string s) String tolowercase() String touppercase() int indexof(string s) int lastindexof(string s) boolean equals(string s) boolean equalsignorecase(string s) String substring(int begin) String substring(int begin, int end) boolean startswith(string prefix) boolean startswith(string pre, int off) string trim() Returns number of characters in the String Returns the character at the specified index of the String Returns true iff string s is in this string, otherwise false Returns a new string that is the lowercase version of this string. Returns a new string that is the UPPERCASE version of this string. Returns the index within this string of the first character of the first occurrence of the specified string s or -1 if not found. Returns the index within this string of the first character of the last occurrence of the specified string s or -1 if not found. Returns true if the contents of this String is the same as the contents of String s. Returns true iff the contents of the this string is the same as that of the string s, ignoring differences in case. Returns a new string that is a substring of this string starting at begin to the end of this string. Returns a new string that is a substring of this string starting at index begin up to but not including end. Returns true iff this string starts with the specified prefix prefix, false otherwise. Returns true iff this string starts at the specified offset off with the specified prefix pre, false otherwise. Returns a new string of this with any leading and trailing whitespace removed. c 2018 Williams, Renault CS200 Midterm Exam 2 (P) Page 2 of 7

Class (static) Constant(s) and Methods from the java.lang.math class: static double Math.PI static double random() static double pow(double x, double n) static double sqrt(double n) static double abs(double n) static double ceil(double n) static double sin(double theta) Field that represents the constant π Returns a random value between 0 (inclusive) and 1 (exclusive) Returns x n Returns n Returns the absolute value of n Returns the value of n rounded up to the nearest whole number. Returns the sine of the angle θ (θ is in radians) Other trig methods also available. Methods from the java.util.random class: Random() Creates a new pseudorandom number generator instance. Random(long s) Creates a new pseudorandom number generator seeded with s. int nextint() Returns the next pseudorandom integer value. int nextint(int n) Returns the next pseudorandom integer value between 0 (inclusive) and n (exclusive). double nextdouble() Returns the next pseudorandom double value between 0.0 (inclusive) and 1.0 (exclusive). Methods from the java.io.printstream class: void print(string s) void print(char c) void print(char[] c) void print(int i) void print(double d) void print(boolean b) void println(string s) void println(char c) void println(int i) void println(double d) void println(boolean b) Prints a String. Prints a character. Prints all the characters from the array in order. Prints an int. Prints a double. Prints a boolean. Prints a String followed by a newline. Prints a character followed by a newline. Prints an int followed by a newline. Prints a double followed by a newline. Prints a boolean followed by a newline. Methods from the java.util.scanner class: Scanner(String s) Scanner(System.in) boolean hasnext() boolean hasnextint() boolean hasnextdouble() boolean hasnextline() String next() int nextint() double nextdouble() String nextline() Creates a Scanner to read the String s Creates a Scanner that reads from the keyboard. Returns true if there s another token of input. Returns true if the next token is an int value. Returns true if the next token is a double value. Returns true if there s another line of input. Finds and returns the next complete token from this scanner. Scans the next token of the input as an int. Scans the next token of the input as a double. Advances this scanner past the current line and returns the input that was skipped. c 2018 Williams, Renault CS200 Midterm Exam 2 (P) Page 3 of 7

Methods from the java.util.arraylist class: Note the E s below are replaced with the particular ArrayList s element type. ArrayList() ArrayList<E>() ArrayList(int initcap) ArrayList<E>(int initcap) int size() E[] toarray() boolean contains(e item) int indexof(e item) E get(int index) void add(e item) void add(int index, E item) Constructs an empty array list where elements are type Object with an initial capacity of 10. Constructs an empty array list of the specified element type E with an initial capacity of 10. Constructs an empty array list where elements are type Object with an initial capacity of initcap. Constructs an empty array list of the specified element type E with an initial capacity of initcap. Returns the number of used elements in this list. Returns an array of the specified type of this ArrayList Returns true iff the specified item is in this list, otherwise false. Returns the index of the specified item if it is in this list, otherwise -1. Returns the item at the specified index in this list, throws IndexOutBoundsException if invalid index. Adds the specified item to the end of this list. Adds the specified item by inserting it into this list at the specified index. boolean addall(collection<? extends E> c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection s Iterator. E remove(int index) boolean remove(e item) Removes and returns the item from the specified index. Returns true iff the specified item was removed from this list, otherwise false. Method from the java.util.arrays class: Note the E s below are replaced with the particular array s element type. static String tostring(e[] array) Returns a String representation of the array, consisting of a list of the array s elements as strings separated by commas and enclosed in square brackets ("[]"). static void sort(e[] array) sorts the specified array in memory type E must be Comparable or Comparable<E> static int[] copyof(int[] orig, int newlength) Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. static <E> E[] copyof(e[] orig, int newlength) Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length. static <E> List<E> aslist(e... a) Returns a fixed-size list backed by the specified array. c 2018 Williams, Renault CS200 Midterm Exam 2 (P) Page 4 of 7

Exception Class Inheritance Hierarchy: public class Object public class Throwable extends Object public class Exception extends Throwable public class RuntimeException extends Exception public class ArithmeticException extends RuntimeException public class IndexOutOfBoundsException extends RuntimeException public class ArrayIndexOutOfBoundsException extends IndexOutOfBounds public class StringIndexOutOfBoundsException extends IndexOutOfBounds public class ClassCastException extends RuntimeException public class NullPointerException extends RuntimeException public class NoSuchElementException extends RuntimeException public class InputMismatchException extends NoSuchElementException public class IOException extends Exception public class FileNotFoundException extends IOException public class EOFException extends IOException c 2018 Williams, Renault CS200 Midterm Exam 2 (P) Page 5 of 7

Part 1: Simple Choice (Questions 1 1, 2 points each) 1. The return type of the expression Math.pow(5, 6) * 2 is. A. double B. int c 2018 Williams, Renault CS200 Midterm Exam 2 (P) Page 6 of 7

Part 2: Multiple Choice (Questions 2 2, 3 points each) 2. What will the following code print out when it is run? Scanner scnr = new Scanner("Hello \n\n World!"); String c = scnr.next(); String b = scnr.nextline(); String a = scnr.next(); System.out.println(":" + a + ":" + b + ":"); A. :World!: : B. : : World!: C. :Hello:World!: D. :Hello: : c 2018 Williams, Renault CS200 Midterm Exam 2 (P) Page 7 of 7