CSE 2221 Midterm Exam #1 SAMPLE



Similar documents
This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output:

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Sample CSE8A midterm Multiple Choice (circle one)

Data Structures and Algorithms Written Examination

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Data Integration through XML/XSLT. Presenter: Xin Gu

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Lecture J - Exceptions

Introducing Variance into the Java Programming Language DRAFT

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 1 October 14, Instructions

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Introduction to Java

Part I. Multiple Choice Questions (2 points each):

AP Computer Science Java Mr. Clausen Program 9A, 9B

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc.

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

Introduction to Object-Oriented Programming

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

WIRIS quizzes web services Getting started with PHP and Java

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Building Java Programs

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Install Java Development Kit (JDK) 1.8

arrays C Programming Language - Arrays

My IC Customizer: Descriptors of Skins and Webapps for third party User Guide

Data Mining Historic Stock Quotes in Java

InternetVista Web scenario documentation

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Object Oriented Software Design

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

In this Chapter you ll learn:

Coding Standard for Java

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

XSLT Mapping in SAP PI 7.1

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

CMSC 202H. ArrayList, Multidimensional Arrays

COMPUTER SCIENCE. Paper 1 (THEORY)

B.Sc (Honours) - Software Development

Algorithms and Data Structures Written Exam Proposed SOLUTION

Arrays in Java. Working with Arrays

Collections.sort(population); // Método de ordenamiento

BS1000 command and backlog protocol

Java Crash Course Part I

Example. Represent this as XML

(Eng. Hayam Reda Seireg) Sheet Java

Interactive Data Visualization for the Web Scott Murray

Topic 11 Scanner object, conditional execution

Building Queries in Microsoft Access 2007

HP AppPulse Mobile. Adding HP AppPulse Mobile to Your Android App

xmlns:emcs=" xmlns:tms="

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Efficient Data Structures for Decision Diagrams

SEZ SEZ Online Manual- DSC Signing with Java Applet. V Version 1.0 ersion 1.0

CompSci-61B, Data Structures Final Exam

Object-Oriented Programming in Java

HTML, CSS, XML, and XSL

Two-Dimensional Arrays. Multi-dimensional Arrays. Two-Dimensional Array Indexing

J a v a Quiz (Unit 3, Test 0 Practice)

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Section 6 Spring 2013

Two-Dimensional Arrays Summer 2010 Margaret Reid-Miller

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Data Structures. Level 6 C Module Descriptor

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

CmpSci 187: Programming with Data Structures Spring 2015

Building Java Programs

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

CSE 308. Coding Conventions. Reference

LAB MANUAL CS (22): Web Technology

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Windows Presentation Foundation (WPF) User Interfaces

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

D06 PROGRAMMING with JAVA

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Week 2 Practical Objects and Turtles

Introduction: Abstract Data Types and Java Review

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Creating a Simple, Multithreaded Chat System with Java

Overview of Web Services API

Realizing Enterprise Integration Patterns in WebSphere

Chapter 1 Java Program Design and Development

Ambientes de Desenvolvimento Avançados

PIC 10A. Lecture 7: Graphics II and intro to the if statement

The Web Web page Links 16-3

Software documentation systems

Transcription:

CSE 2221 Midterm Exam #1 SAMPLE This is a closed-book, closed-notes, closed-electronic-device, closed-neighbor exam. In accordance with The Ohio State University Code of Student Conduct, I certify that I have neither received nor given aid on this examination, that I shall not discuss the contents of this examination with anyone in CSE 2221 who has not already taken the exam, and that I have not recorded and taken from the room any questions or answers from this exam. Name Signature There are 100 points on the exam plus 5 extra-credit points. Please write your answers on the test sheets, and of course don t forget to write and sign your name on the top sheet. Consider the space allotted as an indication of the expected length of the answer. 1. (15 points; 3 points each) Multiple choice: circle the best response to each. 1.1. In design-by-contract, the code responsible for making sure the precondition (requires clause) is true when a method is called is: A. the client code that calls the method B. the code that implements the method C. both the client and the implementation code D. neither the client nor the implementation code 1.2. Consider the following method signature: private static int examscore(int studentnumber) {...} Here, studentnumber is called: A. a distinguished variable B. an argument (or actual parameter) C. a formal parameter D. an index page 1

1.3. Suppose the method from question 1.2 is called in the following statement: int k = examscore(42); This call would certainly: A. be illegal in Java (i.e., it s a compile-time error) B. cause the program to crash when it is executed (i.e., it s a run-time error) C. print out the exam score of student #42 D. assign an exam score of 42 to student k E. be legal in Java (though flagged by CheckStyle) 1.4. Suppose you want to set the double variable onetothree to a random real number uniformly distributed in the interval [1.0, 3.0). You have made the following declaration: Random r = new Random1L(); noting that r.nextdouble() returns a random real number uniformly distributed in the interval [0.0, 1.0). Which statement will set onetothree to the desired result? A. onetothree = 3.0 * r.nextdouble(); B. onetothree = 1.0 + 2.0 * r.nextdouble(); C. onetothree = 1.0 + r.nextdouble() + r.nextdouble(); D. onetothree = r.nextdouble() + r.nextdouble() + r.nextdouble(); 1.5. Suppose you want to display the image file brutus.jpg in a browser, along with other content as organized in the HTML file index.html. Both these files are in the same folder/directory. Which HTML code fragment in index.html will produce the desired result? (Note that a well-formed HTML document such as the one you were to create for project #1 is an XML document.) A. <html>brutus.jpg</html> B. <img src="brutus.jpg" /> C. <p type="image">brutus.jpg</p> D. <a href="brutus.jpg" /> page 2

2. (3 points) Short answer: give a clear and concise response. 2.1. (2 points) When CheckStyle warns you about a magic number in your code, what does this mean? Explain briefly why this warning is something you, as a software professional, should pay attention to and consider fixing (even if you decide not to change your code to remove the warning for a mere class assignment). 2.2. (1 point) Show the value of x after this statement: double x = 1/2; 3. (17 points) Complete the tracing table below. int 1; Code State (Variable Values) int 2; while (i < j) { i * i + 1; j + 2; } page 3

4. (20 points) 4.1. (15 points) Write the body of this method. /** * Returns the smallest value in a. * * @param a * an array of ints * @return smallest value in the array a * @requires * a.length >= 1 * @ensures * minimum = [the smallest value in a] */ private static int minimum(int[] a) { } 4.2. (5 points) Clearly and concisely explain why the precondition is important here. page 4

5. (10 points) Trace the effect of the line of code below that calls squareandreset by tracing the execution of the method body of squareandreset for this call. Tracing table for the call: Code State (Variable Values) num = 13.0 double sq = squareandreset(num); num = sq = Tracing table for squareandreset: Code private static double squareandreset (double x) { State (Variable Values) x = double square = x * x; x = square = x = 0.0; x = square = } return square; page 5

6. (20 points) Complete the body of main so it prompts the user for a password candidate until either the password candidate is the empty string, or the password candidate is acceptable according to isok. (In our formal specifications, for a mathematical string such as pwd, pwd means the length of pwd.) /** * Checks whether the given string satisfies the criteria for * an acceptable password. * * @param pwd * the string to check for acceptability * @requires * pwd > 0 * @ensures * isok = [pwd satisfies the criteria for an acceptable password] */ private static boolean isok(string pwd) {...} /** * Main method. * * @param args * the command line arguments */ public static void main(string[] args) { SimpleReader in = new SimpleReader1L(); SimpleWriter out = new SimpleWriter1L(); } in.close(); out.close(); page 6

7. (9 points) The following is a valid XML document. <?xml version="1.0"?> <buckeyes> <location stadium="home" /> <game opp="uab" date="22 Sep 2012"> <forecast>sunny with 90% probability of football</forecast> </game> </buckeyes> 7.1. (8 points) Draw the XMLTree associated with this document. (Don t worry about drawing the tag icon; just include the enclosing brackets <...> for each label that is a tag.) 7.2. (1 point) How many children does the root node of this XMLTree have? page 7

8. (6 points) The following is not a valid XML document. Circle the locations of three nonoverlapping errors that make it invalid, briefly explaining each error in the space below. <?xml version="1.0"?> <pony> <unicorn mark="three lozenges">rarity <color>cyan</unicorn> </color> <unicorn mark="six-pointed star">twilight Sparkle</unicorn> <unicorn mark="two dolphins" version="g4" /> </pony> <dragon> <youth>spike </dragon> 9. (5 points extra credit) Which area is larger: the shaded area in the figure on the left (a circle inscribed in a square) or the shaded area in the figure on the right (a quarter-circle inscribed in the same size square)? Justify your answer in clear and concise terms. page 8