This midterm has about 4 questions more than the actual midterm of 200 pts will have

Size: px
Start display at page:

Download "This midterm has about 4 questions more than the actual midterm of 200 pts will have"

Transcription

1 C Sc 227 Practice Midterm Name 246 points This midterm has about 4 questions more than the actual midterm of 200 pts will have 1. Write a checkmark to the right of any assertion in the following test method if it would pass. Leave the line in the comment blank if the assertion would fail. public void testexpressions() { int j = 5; int k = 3; double x = -1.5; String s = "U of Arizona"; assertequals(2, j / k); assertequals(1, j % k); assertequals(-0.5, x + 1, 1e-12); assertequals('u', s.charat(1)); // a. // b. // c. // d. assertequals(5, s.indexof("arizona")); // e. assertequals(0, s.indexof("u of A")); // f. assertequals(2.0, Math.sqrt(j), 1e-12); // h. asserttrue(s.compareto("asu") > 0); // i. assertequals(6, s.compareto("u of A")); // j. assertequals(3, s.compareto("u of D")); // k. 2a. Complete the unit test for method grade (fill in the blanks) so it executes every branch of code in the nested selection. Assume the method grade will be in the same class as the method. Implement the following grading policy (10pts) Percentage Grade 90.0 >= percentage "A" 80.0 >= percentage < 90.0 "B" 70.0 >= percentage < 80.0 "C" 60.0 >= percentage < 70.0 "D" percentage < 60.0 "E" assertequals( ); assertequals( ); assertequals( ); assertequals( ); assertequals( ); 2b. Complete method grade as a method in the same class as the assertions above. (8pts) public String grade(double percent) { 1

2 3. How many times will each code fragment print "Hello"? zero and Infinite are legitimate answers (12pts, 4pts each) int j = 1; int n = 5; while(j <= n) { System.out.print("Hello"); n++; int j = 1; while(j <= 11) { System.out.print("Hello"); j = j + 3; int n = 0; for(int j = 1; j < n; j++) { System.out.print("Hello"); // Tricky Question for(int j = 1; j <= 11; j++); System.out.print("Hello"); 4. Complete method occurencesof to return how often a particular int is found in the Scanner argument's input String. These assertions that help explain the expected output must pass. (10pts) Scanner scanner = new Scanner(" "); assertequals(3, cf.occurencesof(11, scanner)); Scanner scanner2 = new Scanner(" "); assertequals(2, cf.occurencesof(6, scanner2)); // Precondition: scanner has only valid integers to scan public int occurencesof(int target, Scanner scanner) { 5. Complete method mirrorends that given a string, looks for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or more characters at the very beginning of the given string, and at the very end of the string in reverse order (possibly overlapping). For example, "abxyzba" has the mirror end "ab". (10pts) assertequals("", cf.mirrorends("")); assertequals("", cf.mirrorends("abcde")); assertequals("a", cf.mirrorends("abca")); assertequals("aba", cf.mirrorends("aba")); public String mirrorends(string str) { 2

3 6. Complete method exists to return true if the String argument is found at least once in an array of Strings. If the string argument target is not found, return false. (10pts) String[] names = { "Li", "Devon", "Sandeep", "Chris", "Regan" ; asserttrue(af.exists("li", names, 5)); asserttrue(af.exists("sandeep", names, 5)); assertfalse(af.exists("not HERE", names, 5)); public boolean exists(string target, String[] a, int n) { 7. Complete method post4 such that when given a non-empty array of ints, post4 returns a new array containing the elements from the original array that come after the right most 4 in the original array argument. The array argument will always contain at least one 4. (14pts) assertarrayequals(new int[] {1, 2, post4(new int[]{2, 4, 1, 2)); assertarrayequals(new int[] {2, post4(new int[]{4, 1, 4, 2)); assertarrayequals(new int[] {1, 2, 3, post4(new int[]{4, 4, 1, 2, 3)); assertarrayequals(new int[] {, post4(new int[]{4)); // Precondition: The array argument is never an empty array and always contains at least one 4 public int[] post4(int[] nums) { 3

4 8. In class String227 complete the equals method to return true if two String227 objects have the same exact characters at the same indexes and their lengths are the same. Return false otherwise. You may not use any String227 methods other than the constructor, charat(int), and length(). public void testequals() { char[] a1 = { 'A', 'B', 'C' ; char[] a2 = { 'A', 'B', 'C' ; char[] a3 = { 'A', 'B', 'C', 'D' ; char[] a4 = { 'D', 'E', 'F' ; String227 str1 = new String227(a1); String227 str2 = new String227(a2); String227 str3 = new String227(a3); String227 str4 = new String227(a4); asserttrue(str1.equals(str1)); asserttrue(str1.equals(str2)); assertfalse(str1.equals(str3)); assertfalse(str1.equals(str4)); assertfalse(str1.equals(str4)); public class String227 implements Comparable<String227> { private char[] thechars; private int n; public String227(char[] a) { thechars = new char[128]; n = a.length; for (int i = 0; i < n; i++) { thechars[i] = a[i]; public char charat(int index) { return thechars[index]; public int length() { return n; public String tostring() { String result = ""; for (int i = 0; i < n; i++) result += thechars[i]; return result; public boolean equals(string227 other) 4

5 9. In the same class String227, complete method compareto to class String227 so it returns the difference of the first character found that differs, a negative int if this String227 is less than the argument, a positive int if this String227 object is greater than the argument. If all characters are exactly equal, return 0. If both String227 objects have the same exact characters up to the end of the shorter string, return the difference in lengths: "abcde".comparto("ab") returns 3 public void testcompareto() { char[] chars1 = { 'a', 'b', 'c', 'd' ; String227 str1 = new String227(chars1); char[] chars2 = { 'a', 'b', 'f', 'd' ; String227 str2 = new String227(chars2); char[] chars3 = { 'a', 'b', 'c', 'd', 'e', 'f' ; String227 str3 = new String227(chars3); assertequals(-3, str1.compareto(str2)); assertequals(+3, str2.compareto(str1)); assertequals(-2, str1.compareto(str3)); assertequals(+2, str3.compareto(str1)); assertequals(0, str3.compareto(str3)); assertequals(0, str2.compareto(str2)); assertequals(0, str1.compareto(str1)); public int compareto(string227 other) { 5

6 10. In the Matrix class, complete method putsumindiagonal that places the sum of each row on the diagonal with all other elements set to 0. It should work for any initial values set in the constructor (even if initial values are set to random integers). The output shown to the right of the method that generates that output shows the expected result public void testputsumindiagonal() { int[][] twodarray = { { 1, 2, 3, 4, { 2, 3, 4, 5, { 3, 4, 5, 6, { 4, 5, 6, 7 ; Matrix m = new Matrix(twoDarray); System.out.println(m.toString()); m.putsumindiagonal(); System.out.println(m.toString()); Output public class Matrix { private int[][] data; private int nrows; private int ncols; public Matrix(int[][] table) { nrows = table.length; ncols = table[0].length; data = new int[nrows][ncols]; for (int i = 0; i < nrows; i++) { for (int j = 0; j < ncols; j++) { data[i][j] = table[i][j]; // Makes a clone of the 2D array argument public String tostring() { String result = ""; for (int row = 0; row < nrows; row++) { for (int col = 0; col < ncols; col++) { result += " " + data[row][col]; result += "\n"; return result; public void putsumindiagonal() { 6

7 11. As part of the same Matrix class from the previous page, complete method mirrored()to change data to the mirror image of itself with the top row moved to the bottom row, the 2 nd row to the 2 nd to last row and so on. All elements in each row must also be the mirror image. For example, the 2D arrays data should be changed like these two: (16pts) data before data after data before data after public void mirrored() { // you have access to data, nrows, and ncols 12. Determine the tightest upper bound runtimes of the following loops. Express your answer in the Big-O notation we have been using in class (assume the initialization int sum = 0;). (24pts: 3pts each for order, 6pts for overall style) a. for (int j = n; j >= 0; j--) b. for (int j = 1; j <= n; j = j + 2) c. for(int k = 1; k <= n; k = 2 * k) d. for( int j = 1; j <= n; j++ ) for( int k = 1; k <= n; k++ ) for(int m = 1; m <= n; m++ ) e. int j = 1; f. for(int k = 1; k <= n; k = 2 * k) for (int j = 1; j <= 4 * n; j = j + 2) 7

8 13. Write an X in the comment to the right of all statements that compile. (3pts) Object anobject = new Integer(3); // a. Object otherobject = "a string"; // b. Integer anint = new Object(); // c. 14. Write an X in the comment to the right of all statements that compile. (3pts) Integer i1 = 3; // a. int i2 = new Integer(-1); // b. Object obj = 3; // c. 15. Write an X in the comment to the right of all statements that compile. (3pts) Object[] elements = new Object[5]; // a. elements[0] = 12; // b. elements[1] = "Second"; // c. 16. Will this code compile, yes or no? (2pts) Object obj = 3; Integer anint = obj; 17. Will this code generate a compiletime error, yes or no? (2pts) Object obj = 3; String str = (String)obj; 18. Will this code generate a runtime error (an exception) when it is run, yes or no? (2pts) Object obj = 3; String str = (String)obj 19. Write DS if it's a data structure, COLL if it's a collection class or ADT if an abstract data type (9pts) a. Bag b. singly-linked structure c. Comparable d. binary tree e. int[] f. double[][] g. Set h. LinkedSet i. PriorityList 20. What is testing for? = IllegalArgumentException.class) public void testwhat() { PriorityList<String> list1 = new ArrayPriorityList<String>(); list1.insertelementat(1, "Eric"); 21. In above, why is it possible to store an ArrayPriorityList in a variable of type PriorityList? (2pts) 8

9 22. Use our familiar Node class (shown below with data and next instance variables) and this view of a linked structure to answer the questions a) through d) a) What is the value of first.data? (2pts) b) What is the value of first.next.next.data? (2pts) c) What reference value equals first.next.next.next? (2pts) d) Write the code that prints all values. Make the code general enough to work on any sized linked structure where the last node references the first (this is a circular linked list) (6pts) 23. Write Java code that will generate the singly-linked structure to the right assuming you have access to class Node (4pts) 24. Draw a picture of a singly-linked structure created with this code assuming you have access to class Node (4pts) Node last = new Node("A"); Node temp = new Node("B"); temp.next = last; last.next = temp; 25. On the next page, write a) method reverse() so all elements are stored in reverse order. Also write b) method addlast(e) to add elements to the end of the LinkedList. The code in the box (see next page) must compile with passing assertions. You cannot pretend there are other LinkedList methods. If you need another, write it. public class LinkedList<E extends Comparable<E>> { private class Node { private E data; private Node next; public Node(E objectreference) { data = objectreference; public Node(E objectreference, Node nextreference) { data = objectreference; next = nextreference; private Node first; private int n; public LinkedList() { first = null; n = 0; 9

10 public void addfirst(e element) { first = new Node(element, first); n++; public int size() { return n; public String tostring() { if (first == null) return "[]"; else if (first.next == null) return "[" + first.data + "]"; else { String result = "[";d Node ref = first; while (ref.next!= null) { result += ref.data + ", "; ref = ref.next; result = result + ref.data + "]"; return result; public void reverse() { // 12 public void testreverse() { LinkedList<String> list = new LinkedList<String>(); list.addfirst("a"); list.addfirst("b"); list.addfirst("c"); assertequals("[c, B, A]", list.tostring()); list.reverse(); assertequals("[a, B, C]", public void testaddlast() { LinkedList<String> list = new LinkedList<String>(); list.addlast("a"); list.addlast("b"); list.addlast("c"); list.addlast("d"); assertequals(4, list.size()); // Is size correct? assertequals("[a, B, C, D]", list.tostring()); public void addlast(e el) { // 10 pts 10

11 26. To the same LinkedList class on the previous page, complete method removeall(e element) as a method in LinkedList<E> so it removes all occurrences of element from any LinkedList object. Assume type E has an equals method. These assertions must pass. (16pts) LinkedList<String> list = new LinkedList<String>(); list.addfirst("b"); list.addfirst("a"); list.addfirst("b"); list.addfirst("b"); assertequals("[b, B, A, B]", list.tostring()); assertequals(3, list.size()); list.removeall("b"); assertequals("[a]", list.tostring()); assertequals(1, list.size()); public void removeall(e element) { 11

C Sc 227 Practice Test 2 Section Leader Name 134pts

C Sc 227 Practice Test 2 Section Leader Name 134pts C Sc 227 Practice Test 2 Section Leader Name 134pts 1. Determine the tightest upper bound runtimes of the following loops. Express your answer in the Big-O notation we have been using in class (assume

More information

C Sc 227 Practice Test 2 Section Leader Name 134pts ANSWERS

C Sc 227 Practice Test 2 Section Leader Name 134pts ANSWERS C Sc 227 Practice Test 2 Section Leader Name 134pts ANSWERS 1. Determine the tightest upper bound runtimes of the following loops. Express your answer in the Big-O notation we have been using in class

More information

C Sc 227 Practice Test 2 Section Leader Your Name 100pts. a. 1D array b. PriorityList<E> c. ArrayPriorityList<E>

C Sc 227 Practice Test 2 Section Leader Your Name 100pts. a. 1D array b. PriorityList<E> c. ArrayPriorityList<E> C Sc 227 Practice Test 2 Section Leader Your Name 100pts 1. Approximately how many lectures remain in C Sc 227 (give or take 2)? (2pts) 2. Determine the tightest upper bound runtimes of the following loops.

More information

C Sc 227 Practice Final

C Sc 227 Practice Final C Sc 227 Practice Final Name 1. Use the Node class shown question 13 on this page below with data and next instance variables and this view of a linked structure to answer the questions a) through d) a)

More information

C Sc 227 Practice Final Summer 13 Name 200 pts

C Sc 227 Practice Final Summer 13 Name 200 pts C Sc 227 Practice Final Summer 13 Name 200 pts 1. Use our familiar Node class (shown below with data and next instance variables) and this view of a linked structure to answer the questions a) through

More information

1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (not in Tucson)

1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (not in Tucson) 1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (not in Tucson) 2. Use our familiar Node class (shown below with data and next instance variables) and this view

More information

C Sc 227 Practice Final Summer 12 Name 200pt

C Sc 227 Practice Final Summer 12 Name 200pt C Sc 227 Practice Final Summer 12 Name 200pt 1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (I'm not in Tucson) 2. Use our familiar Node class (shown below with

More information

Implement factorial to return n! that is defined as n * n-1 * n-2 * n-3 * 2 * 1. 1! And 0! Are both defined as 1. Use recursion, no loop.

Implement factorial to return n! that is defined as n * n-1 * n-2 * n-3 * 2 * 1. 1! And 0! Are both defined as 1. Use recursion, no loop. RecursionFun Collaboration: Solo Work on this project alone. Do not copy any code from anywhere, other than from our website, book, or lecture notes. Do not look at another person's screen or printout.

More information

C Sc 127A Practice Test 2 SL Name 150pts

C Sc 127A Practice Test 2 SL Name 150pts C Sc 127A Practice Test 2 SL Name 150pts 0. What is the capiatal of Canada? f (4pts) Just do not leave this blank, any answer would do a. Toronto b. Quebec c. Ottawa d. Vancouver e. Calgary f. Not sure

More information

0. What is the capital of Canada? (4pts) a. Toronto b. Quebec c. Ottawa d. Vancouver e. Calgary f. Not sure

0. What is the capital of Canada? (4pts) a. Toronto b. Quebec c. Ottawa d. Vancouver e. Calgary f. Not sure 150pts 0. What is the capital of Canada? (4pts) a. Toronto b. Quebec c. Ottawa d. Vancouver e. Calgary f. Not sure 1. Use this initialization to answer the questions that follow: int[] x = new int[100];

More information

A Linked Structure. Chapter 17

A Linked Structure. Chapter 17 Chapter 17 A Linked Structure This chapter demonstrates the OurList interface implemented with a class that uses a linked structure rather than the array implementation of the previous chapter. The linked

More information

C Sc 127B Practice Test 2 Section Leader Your Name 100pts

C Sc 127B Practice Test 2 Section Leader Your Name 100pts C Sc 127B Practice Test 2 Section Leader Your Name 100pts Assume we have two collection class named Stack and Queue that have the appropriate messages: Stack public boolean isempty(); public void push(e

More information

Programming Project: ArrayFun

Programming Project: ArrayFun Programming Project: ArrayFun Collaboration: Solo with help from classroom/online resources, Lane, and/or Rick. Anyone can also share thoughts about any specification and possible algorithm, but no sharing

More information

CS 307 Midterm 2 Fall 2010

CS 307 Midterm 2 Fall 2010 Points off 1 2 3 4 Total off Net Score Exam Number: CS 307 Midterm 2 Fall 2010 Name UTEID login name TA's Name: Harsh Yi-Chao (Circle One) Instructions: 1. Please turn off your cell phones and other electronic

More information

Stacks and Queues. Chapter Stacks

Stacks and Queues. Chapter Stacks Chapter 18 Stacks and Queues 18.1 Stacks The stack abstract data type allows access to only one element the one most recently added. This location is referred to as the top of the stack. Consider how a

More information

Generic Collections. Chapter The Object class

Generic Collections. Chapter The Object class Chapter 13 Generic Collections Goals Introduce class Object and inheritance Show how one collection can store any type of element using Object[] 13.1 The Object class The StringBag class shown of Chapter

More information

Interfaces. Chapter Java Interfaces

Interfaces. Chapter Java Interfaces Chapter 14 Interfaces Goals Understand what it means to implement a Java interface Use the Comparable interface to have any type of elements sorted and binary searched Show how a Java interface can specify

More information

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts

More information

Recursion. Chapter Simple Recursion. Goals Trace recursive algorithms Implement recursive algorithms

Recursion. Chapter Simple Recursion. Goals Trace recursive algorithms Implement recursive algorithms Chapter 19 Recursion Goals Trace recursive algorithms Implement recursive algorithms 19.1 Simple Recursion One day, an instructor was having difficulties with a classroom s multimedia equipment. The bell

More information

Repetition. Chapter 6

Repetition. Chapter 6 Chapter 6 Repetition Goals This chapter introduces the third major control structure repetition (sequential and selection being the first two). Repetition is discussed within the context of two general

More information

Repetition. Chapter 6

Repetition. Chapter 6 Chapter 6 Repetition Goals This chapter introduces the third major control structure repetition (sequential and selection being the first two). Repetition is discussed within the context of two general

More information

CS 307 Final Fall 2009

CS 307 Final Fall 2009 Points off 1 2 3 4 5 6 Total off Net Score CS 307 Final Fall 2009 Name UTEID login name Instructions: 1. Please turn off your cell phones. 2. There are 6 questions on this test. 3. You have 3 hours to

More information

CS 307 Midterm 2 Spring 2008

CS 307 Midterm 2 Spring 2008 Points off 1 2 3 4 Total off Net Score Exam Number: CS 307 Midterm 2 Spring 2008 Name UTEID login name TA's Name: Mario Ruchica Vishvas (Circle One) Instructions: 1. Please turn off your cell phones and

More information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

Collection Considerations

Collection Considerations Chapter 15 Collection Considerations Goals Distinguish Collection classes, data structures, and ADTs Consider three data structures used in this textbook: array, singly linked, and tree Observe that a

More information

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM : CIS 110 Introduction to Computer Programming Summer 2018 Midterm Name: Recitation ROOM : Pennkey (e.g., paulmcb): My signature below certifies that I have complied with the University of Pennsylvania s

More information

CS 312 Midterm 2 Fall 2013

CS 312 Midterm 2 Fall 2013 CS 312 Midterm 2 Fall 2013 SOLUTION SOLUTION SOLUTION SOLUTION SOLUTION Problem Number Topic Points Possible 1 code trace 28 2 arrays 14 3 strings 16 4 program logic 16 5 scanner 23 6 arrays and strings

More information

Test 1: CPS 100. Owen Astrachan. October 1, 2004

Test 1: CPS 100. Owen Astrachan. October 1, 2004 Test 1: CPS 100 Owen Astrachan October 1, 2004 Name: Login: Honor code acknowledgment (signature) Problem 1 value 20 pts. grade Problem 2 30 pts. Problem 3 20 pts. Problem 4 20 pts. TOTAL: 90 pts. This

More information

CS 307 Midterm 2 Fall 2008

CS 307 Midterm 2 Fall 2008 Points off 1 2 3 4 5 Total off Net Score Exam Number: CS 307 Midterm 2 Fall 2008 Name UTEID login name TA's Name: Mikie Ron Sarah (Circle One) Instructions: 1. Please turn off your cell phones and other

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26 Due before lecture on Wednesday, September 26 Getting Started Before starting this assignment, make sure that you have completed Problem Set 0, which can be found on the assignments page of the course

More information

public static<e> List<E> removeoccurrences(list<e> origlist, E remove) {

public static<e> List<E> removeoccurrences(list<e> origlist, E remove) { CS 201, Fall 2008 Nov 19th Exam 2 Name: Question 1. [10 points] Complete the following generic method. It should return a list containing all of the elements in origlist, in order, except the elements

More information

CS 314 Midterm 2 Fall 2012

CS 314 Midterm 2 Fall 2012 Points off 1 2 3 4 5 Total off Net Score CS 314 Midterm 2 Fall 2012 Your Name_ Your UTEID Circle yours TA s name: John Zihao Instructions: 1. There are 5 questions on this test. 2. You have 2 hours to

More information

C Sc 127B Practice Test 3 Section Leader Name 100 pts

C Sc 127B Practice Test 3 Section Leader Name 100 pts C Sc 127B Practice Test 3 Section Leader Name 100 pts 1. Use the following binary tree to write out each of the three traversals indicated below. (12pts) 1 2 3 4 5 6 Preorder traversal Inorder traversal

More information

More non-primitive types Lesson 06

More non-primitive types Lesson 06 CSC110 2.0 Object Oriented Programming Ms. Gnanakanthi Makalanda Dept. of Computer Science University of Sri Jayewardenepura More non-primitive types Lesson 06 1 2 Outline 1. Two-dimensional arrays 2.

More information

Points off Total off Net Score. CS 314 Final Exam Spring 2017

Points off Total off Net Score. CS 314 Final Exam Spring 2017 Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2017 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.

More information

CS 307 Midterm 2 Fall 2009

CS 307 Midterm 2 Fall 2009 Points off 1 2 3 4 5 Total off Net Score Exam Number: CS 307 Midterm 2 Fall 2009 Name UTEID login name TA's Name: Oswaldo Rashid Swati (Circle One) Instructions: 1. Please turn off your cell phones and

More information

Programming Project: Game of Life

Programming Project: Game of Life Programming Project: Game of Life Collaboration Solo: All work must be your own with optional help from UofA section leaders The Game of Life was invented by John Conway to simulate the birth and death

More information

In this chapter, you will:

In this chapter, you will: Java Programming: Guided Learning with Early Objects Chapter 4 Control Structures I: Selection In this chapter, you will: Make decisions with the if and if else structures Use compound statements in an

More information

CS 307 Midterm 2 Spring 2011

CS 307 Midterm 2 Spring 2011 Points off 1 2 3 4 5 Total off Net Score Exam Number: CS 307 Midterm 2 Spring 2011 Name UTEID login name TA's Name: Dan Muhibur Oliver (Circle One) Instructions: 1. Please turn off your cell phones and

More information

CS 307 Final Spring 2009

CS 307 Final Spring 2009 Points off 1 2 3 4 5 Total off Net Score CS 307 Final Spring 2009 Name UTEID login name Instructions: 1. Please turn off your cell phones. 2. There are 5 questions on this test. 3. You have 3 hours to

More information

Arrays. Chapter The Java Array Object. Goals

Arrays. Chapter The Java Array Object. Goals Chapter 7 Arrays Goals This chapter introduces the Java array for storing collections of many objects. Individual elements are referenced with the Java subscript operator []. After studying this chapter

More information

CS 314 Final Spring 2013 SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION

CS 314 Final Spring 2013 SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Spring 2013 SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION Your UTEID Instructions: 1. There are 6 questions on this

More information

CS 314 Midterm 1 Fall 2011

CS 314 Midterm 1 Fall 2011 Points off 1 2 3 4 5 Total off Net Score CS 314 Midterm 1 Fall 2011 Your Name_ Your UTEID Circle yours TA s name: Swati Yuanzhong Instructions: 1. There are 5 questions on this test. 2. You have 2 hours

More information

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY Objectives Declaration of 1-D and 2-D Arrays Initialization of arrays Inputting array elements Accessing array elements Manipulation

More information

CS 307 Midterm 1 Spring 2009

CS 307 Midterm 1 Spring 2009 Points off 1 2 3 4 Total off Net Score CS 307 Midterm 1 Spring 2009 Your Name Your UTEID Circle yours TA s name: Todd Guhan Xiuming(aka David) Instructions: 1. Please turn off or silence your cell phones.

More information

CS 314 Exam 2 Spring 2018

CS 314 Exam 2 Spring 2018 Points off 1 2 3 4 5 Total off CS 314 Exam 2 Spring 2018 Your Name Your UTEID Circle your TA's Name: Aish Anthony Chris Dayanny Hailey Ivan Jacob Joseph Lucas Shelby Instructions: 1. There are 5 questions

More information

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March 2006 11.05-12.35 Please fill in your Examination Number here: Student Number here: MODEL ANSWERS All

More information

Csci 102: Sample Exam

Csci 102: Sample Exam Csci 102: Sample Exam Duration: 65 minutes Name: NetID: Student to your left: Student to your right: DO NOT OPEN THIS EXAM UNTIL INSTRUCTED Instructions: Write your full name and your NetID on the front

More information

Programming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures

Programming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures Chapter 4: Control Structures I Java Programming: Program Design Including Data Structures Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form

More information

Binary Search Trees. Chapter 21. Binary Search Trees

Binary Search Trees. Chapter 21. Binary Search Trees Chapter 21 Binary Search Trees Binary Search Trees A Binary Search Tree is a binary tree with an ordering property that allows O(log n) retrieval, insertion, and removal of individual elements. Defined

More information

Strings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Strings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics Strings Strings and their methods Produced by: Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Primitive Types: char Object Types: String Primitive vs Object Types

More information

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams. CS 61A, Fall, 2002, Midterm #2, L. Rowe 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams. a) d) 3 1 2 3 1 2 e) b) 3 c) 1 2 3 1 2 1 2 For each of the following Scheme

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CS 314 Exam 2 Spring

CS 314 Exam 2 Spring Points off 1 2 3 4 5 Total off CS 314 Exam 2 Spring 2017 Your Name Your UTEID Instructions: 1. There are 5 questions on this test. 100 points available. Scores will be scaled to 200 points. 2. You have

More information

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects CS200: Computer Science I Module 19 More Objects Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 Class API a class API can contain three different types of methods: 1. constructors

More information

C Sc 127B Practice Test 3 Section Leader Name 100 pts

C Sc 127B Practice Test 3 Section Leader Name 100 pts C Sc 127B Practice Test 3 Section Leader Name 100 pts 1. Use the following binary tree to write out each of the three traversals indicated below. (15pts) 1 2 3 4 5 6 Preorder traversal Inorder traversal

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

An Introduction to Data Structures

An Introduction to Data Structures An Introduction to Data Structures Advanced Programming ICOM 4015 Lecture 17 Reading: Java Concepts Chapter 20 Fall 2006 Adapded from Java Concepts Companion Slides 1 Chapter Goals To learn how to use

More information

I. True/False: (2 points each)

I. True/False: (2 points each) CS 102 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2008 What is your name?: (2 points) There are three sections: I. True/False..............54 points; (27 questions, 2 points each)

More information

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code

More information

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Points off Total off Net Score. CS 314 Final Exam Spring 2016 Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2016 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.

More information

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012 CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012 Name: This exam consists of 7 problems on the following 6 pages. You may use your single- side hand- written 8 ½ x 11 note sheet during the

More information

CSE 143 SAMPLE MIDTERM

CSE 143 SAMPLE MIDTERM CSE 143 SAMPLE MIDTERM 1. (5 points) In some methods, you wrote code to check if a certain precondition was held. If the precondition did not hold, then you threw an exception. This leads to robust code

More information

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do: Project MindNumber Collaboration: Solo. Complete this project by yourself with optional help from section leaders. Do not work with anyone else, do not copy any code directly, do not copy code indirectly

More information

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Spring Written Exam 1 COS 126 General Computer Science Spring 2017 Written Exam 1 This exam has 9 questions (including question 0) worth a total of 70 points. You have 50 minutes. Write all answers inside the designated spaces.

More information

Chapter 4: Control Structures I

Chapter 4: Control Structures I Chapter 4: Control Structures I Java Programming: From Problem Analysis to Program Design, Second Edition Chapter Objectives Learn about control structures. Examine relational and logical operators. Explore

More information

CS 314 Midterm 2 Spring 2013

CS 314 Midterm 2 Spring 2013 Points off 1 2 3 4 5 Total off Net Score CS 314 Midterm 2 Spring 2013 Your Name Your UTEID Circle yours TA s name: Donghyuk Lixun Padmini Zihao Instructions: 1. There are 5 questions on this test. The

More information

CS S-08 Arrays and Midterm Review 1

CS S-08 Arrays and Midterm Review 1 CS112-2012S-08 Arrays and Midterm Review 1 08-0: Arrays ArrayLists are not part of Java proper 08-1: Arrays Library class Created using lower-level Java construct: Array Arrays are like a stripped-down

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018 Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment

More information

CS 314 Final Fall 2012

CS 314 Final Fall 2012 Points off 1 2A 2B 2C 3 4A 4B 5 Total off Net Score CS 314 Final Fall 2012 Your Name_ Your UTEID Instructions: 1. There are 5 questions on this exam. The raw point total on the exam is 110. 2. You have

More information

CS 314 Exam 2 Spring 2016

CS 314 Exam 2 Spring 2016 Points off 1 2 3 4 5 6 Total off Raw Score CS 314 Exam 2 Spring 2016 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 200 points.

More information

More on Strings. String methods and equality. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Compu<ng and Mathema<cs h=p://www.wit.

More on Strings. String methods and equality. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Compu<ng and Mathema<cs h=p://www.wit. More on Strings String methods and equality Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Compu

More information

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about

More information

CS 307 Final Spring 2008

CS 307 Final Spring 2008 Points off 1 2 3 4 5 Total off Net Score CS 307 Final Spring 2008 Name UTEID login name Instructions: 1. Please turn off your cell phones. 2. There are 5 questions on this test. 3. You have 3 hours to

More information

CS 307 Final Spring 2011

CS 307 Final Spring 2011 Points off 1 2 3 4A 4B 4C 5A 5B Total Off Net CS 307 Final Spring 2011 Name UTEID login name Instructions: 1. Please turn off your cell phones and all other electronic devices. 2. There are 5 questions

More information

CSE wi: Practice Midterm

CSE wi: Practice Midterm CSE 373 18wi: Practice Midterm Name: UW email address: Instructions Do not start the exam until told to do so. You have 80 minutes to complete the exam. This exam is closed book and closed notes. You may

More information

CMSC132 Summer 2018 Midterm 1

CMSC132 Summer 2018 Midterm 1 CMSC132 Summer 2018 Midterm 1 First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam. Please

More information

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions CS211 Spring 2005 Prelim 1 March 10, 2005 Solutions Instructions Write your name and Cornell netid above. There are 6 questions on 9 numbered pages. Check now that you have all the pages. Write your answers

More information

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 There are 5 problems on the exam, with 56 points total available. There are 10 pages to the exam (5 pages

More information

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 Name: USC loginid (e.g., ttrojan): CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 There are 6 problems on the exam, with 70 points total available. There are 7 pages to the exam, including this one;

More information

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

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)

More information

CSCI-1200 Data Structures Fall 2017 Test 1 Solutions

CSCI-1200 Data Structures Fall 2017 Test 1 Solutions CSCI-1200 Data Structures Fall 2017 Test 1 Solutions 1 Searching for Symbols in ASCII Art [ /24] In this problem we will search a large ASCII Art canvas for matches to a target pattern. For example, given

More information

Java Arrays. What could go wrong here? Motivation. Array Definition 9/28/18. Mohammad Ghafari

Java Arrays. What could go wrong here? Motivation. Array Definition 9/28/18. Mohammad Ghafari 9/28/8 Java Arrays What could go wrong here? int table[][] = new int[2][]; // some code int sum = ; for (int i = ; i < 2; i++) for (int j = ; j < ; j++) int value = table[i][j]; sum += value; Mohammad

More information

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

CS212 Midterm. 1. Read the following code fragments and answer the questions. CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");

More information

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

Facebook. / \ / \ / \ Accenture Nintendo

Facebook. / \ / \ / \ Accenture Nintendo 1. Binary Tree Traversal Consider the following tree: +---+ 4 +---+ 1 9 / / +---+ 6 0 2 +---+ 3 8 \ \ \ \ 7 5 Fill in each of the traversals below : Pre-order: 4 1 6 3 7 0 8 5 9 2 In-order: 3 7 6 1 0 8

More information

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;}

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;} 1. What does mystery(3) return? public int mystery (int n) { int m = 0; while (n > 1) {if (n % 2 == 0) n = n / 2; else n = 3 * n + 1; m = m + 1;} return m; } (a) 0 (b) 1 (c) 6 (d) (*) 7 (e) 8 2. What are

More information

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

CMSC132 Summer 2018 Midterm 1. Solution

CMSC132 Summer 2018 Midterm 1. Solution CMSC132 Summer 2018 Midterm 1 Solution First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam.

More information

4. Write the output that would be printed from each of the following code fragments. (6pts) a = 5 b = 4 temp = a a = b b = temp print(a, b, temp)

4. Write the output that would be printed from each of the following code fragments. (6pts) a = 5 b = 4 temp = a a = b b = temp print(a, b, temp) 1. Write an X To the left of each valid Python names (identifiers). (6pts) a) _ X_ mispelted e) _ X_ t_rex b) _ X_ ident999 f)??? c) 25or6to4 g) H.P. 2. Write an X To the left of each Python reserved words

More information

Problem Grade Total

Problem Grade Total CS 101, Prof. Loftin: Final Exam, May 11, 2009 Name: All your work should be done on the pages provided. Scratch paper is available, but you should present everything which is to be graded on the pages

More information

2. [20] Suppose we start declaring a Rectangle class as follows:

2. [20] Suppose we start declaring a Rectangle class as follows: 1. [8] Create declarations for each of the following. You do not need to provide any constructors or method definitions. (a) The instance variables of a class to hold information on a Minesweeper cell:

More information

Test 1: Compsci 100. Owen Astrachan. February 15, 2006

Test 1: Compsci 100. Owen Astrachan. February 15, 2006 Test 1: Compsci 100 Owen Astrachan February 15, 2006 Name: (2 points) Login: Honor code acknowledgment (signature) Problem 1 value 15 pts. grade Problem 2 12 pts. Problem 3 25 pts. Problem 4 21 pts. TOTAL:

More information

CSE 331 Midterm Exam 2/13/12

CSE 331 Midterm Exam 2/13/12 Name There are 10 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information

ESC101 : Fundamental of Computing

ESC101 : Fundamental of Computing ESC101 : Fundamental of Computing End Semester Exam 19 November 2008 Name : Roll No. : Section : Note : Read the instructions carefully 1. You will lose 3 marks if you forget to write your name, roll number,

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University 9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes

More information

Introduction to Computing II (ITI 1121) Final Examination

Introduction to Computing II (ITI 1121) Final Examination Introduction to Computing II (ITI 1121) Final Examination Instructor: Marcel Turcotte April 2010, duration: 3 hours Identification Student name: Student number: Signature: Instructions 1. 2. 3. 4. 5. 6.

More information