CS 305j Midterm 1 Fall 2006

Similar documents
CS 305j Midterm 1 Fall 2007

CS 305j Midterm 1 Fall 2008

CS 312 Midterm 1 Spring 2013

CS 312 Midterm 1 Spring 2013

CS 305j Midterm 2 Fall 2006

CS 307 Midterm 1 Fall 2007

CS 312 Exam 1 Fall KG Kris Megan Roman Sonika

Garfield AP CS. Graphics

Topic 8 Graphics. Margaret Hamilton

Building Java Programs

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

Topic 8 graphics. -mgrimes, Graphics problem report 134

Building Java Programs

Building Java Programs

CS 112 Introduction to Programming

CS 112 Introduction to Programming

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

CS 307 Midterm 1[corrected] Spring 2008

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

TWO-DIMENSIONAL FIGURES

AP COMPUTER SCIENCE A

CS 177 Recitation. Week 8 Methods

CS 101 Spring 2007 Midterm 2 Name: ID:

Repetition. We might start out with the following program that draws only the left most object.

JAVA OPERATORS GENERAL

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

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

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

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

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

Building Java Programs

Some Sample AP Computer Science A Questions - Solutions

CS 312 Midterm 2 Fall Jose Stas Aaron

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

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

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Instructor: Yu Wang 11/16/2012

CS 312 Midterm 2 Fall 2013

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

Happy Cinco de Mayo!!!!

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

CS 307 Midterm 1 Spring 2009

Topic 9 More Graphics. Based on slides bu Marty Stepp and Stuart Reges from

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

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

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

AP Computer Science Unit 1. Programs

CS 231 Data Structures and Algorithms Fall Arrays Lecture 07 - September 19, Prof. Zadia Codabux

CS 307 Midterm 2 Fall 2010

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2013

CS 314 Midterm 2 Fall 2012

Using Graphics. Building Java Programs Supplement 3G

CS 307 Midterm 2 Fall 2009

Operators Questions

CS 455 Midterm Exam 1 Fall 2013 [Bono] Wednesday, Oct. 2, 2013

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

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

Practice Midterm 1. Problem Points Score TOTAL 50

Lesson 36: for() Loops (W11D1)

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CS 113 MIDTERM EXAM 2 SPRING 2013

CS 455 Midterm Exam 1 Spring 2013 [Bono] Feb. 21, 2013

Final Examination CS 125 Introduction to Computer Science Fall Hours

Declaring and ini,alizing 2D arrays

CSE 142 Sample Midterm Exam #3

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

CS 307 Midterm 2 Fall 2008

CS 307 Midterm 2 Spring 2008

Happy Cinco de Mayo!!!!

CS 100: Programming Assignment P1

Some Practice Midterm Problems

CS 101 Exam 2 Spring Id Name

CS 113 PRACTICE FINAL

Building Java Programs

COMP 110 Programming Exercise: Simulation of the Game of Craps

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

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

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Question: Total Points: Score:

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

Learning Goals LG1: Implement the peer instruction process by A) clicking in on an answer B) discussing with your team C) coming to consensus and

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

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

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

Problem Points Score Grader Total 75

Admin. CS 112 Introduction to Programming. Recap. Example: Nested Loop. Example: Rewrite

SDKs - Eclipse. SENG 403, Tutorial 2

CMP 326 Midterm Fall 2015

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

The FacebookPerson Example. Dr. Xiaolin Hu CSC 2310, Spring 2015

Practice Midterm 1 Answer Key

CS 314 Exam 2 Spring

CISC 1600 Lecture 3.1 Introduction to Processing

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

Learning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods

Write a program which converts all lowercase letter in a sentence to uppercase.

CSE 11 Midterm Fall 2008

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

Transcription:

Points off 1 2 3 4 5 6 7 Total off Net Score CS 305j Midterm 1 Fall 2006 Your Name Your UTEID Circle you TA's name: Brad Jacob Instructions: 1. Please turn off your cell phones 2. There are 7 questions on this test. 3. You will 50 minutes to complete the test. 4. You may not use a calculator. 5. Please make your answers legible. 6. When code is required, write Java code. 1. Expressions. 2 points each, 10 points total. For each Java expression in the left hand column, indicate its value in the right hand column. Be sure to show a constant of the appropriate type. For example, 7.0 rather than 7 for a double, Strings in quotes. A. 3 * 2 + 4 * 3 B. 17 % 9-20 % (26 / 7) C. 2 + 5 + "2" + 2 + 5 D. 2.5 + 5 / 2 + (3 / 0.5) E. 3 * (2 + 4) * 2 / 10 CS 305j Midterm 1 Fall 2006 1

2. Parameters Simulation. 15 points. Consider the following program. public class ParameterQuestion{ public static void main(string[] args){ int a = 2; int b = 3; int c = 2; int x = a + b; int y = a + 1; show(3, 2); show(x, y); show(c, c); show(a, b); System.out.println(a + " " + b); public static void show(int a, int b){ int c = a + b; a = b * 2; System.out.println(a + " " + b + " " + c); List below the output produced by this program when it is run. CS 305j Midterm 1 Fall 2006 2

3. Loops Simulation. 15 points. Consider the following method: public static int loop(int x){ int total = 1; for(int i = 1; i <= x; i++){ total = total * 2; return total; For each method call below what value is returned? Method Call loop(-1); Value Returned loop(0); loop(1); loop(2); loop(3); CS 305j Midterm 1 Fall 2006 3

4. Simulation. 15 points. Sketch the drawing panel window that is produced when the following program when is run. Do not worry about the title bar. import java.awt.*; public class Draw{ public static final int SIZE = 600; public static void main(string[] args){ DrawingPanel p = new DrawingPanel(SIZE, SIZE); Graphics g = p.getgraphics(); int increment = SIZE / 3; int x = 0; int y = 0; // parameters on drawoval are x coordinate, y coordinate, // width, and height for(int row = 1; row <= 3; row++){ x = 0; for(int column = 1; column <= 3; column++){ g.drawoval(x, y, increment, increment); x = x + increment; y = y + increment; // parameters on drawline are the x and y coordinates of the // two endpoints of the line: x1, y1, x2, y2 g.drawline(0, 0, SIZE, SIZE); g.drawline(size, 0, 0, SIZE); Sketch your DrawingPanel produced by the program in the box to the right. CS 305j Midterm 1 Fall 2006 4

5. Loops Simulation. 15 points. Consider the following program. public class NestedLoops{ public static final int SIZE = 5; public static void main(string[] args){ String dot = "."; for(int i = 1; i <= SIZE; i++){ for(int j = i; j <= SIZE; j++){ System.out.print(dot); for(int k = i; k <= SIZE; k++){ System.out.print(i); System.out.println(); List below the output produced by this program when it is run. CS 305j Midterm 1 Fall 2006 5

6. Programming. 15 points. In the imaginary game "Ring the Gack" players throw rings on the antlers of a "Gack", an imaginary creature from Dr. Seuss. Players throw red, blue, and yellow rings onto the antlers. They get 10 points for every red ring that lands on the antlers, 5 points for every blue ring that lands on the antlers, and 1 point for every yellow ring that lands on the antlers. Write a method that given the number of red, blue, and yellow rings a player successfully threw onto the antlers returns the players score. For example if a player had 3 red rings, 5 blue rings, and 2 yellow rings that landed on the antlers their score would be 30 + 25 + 2 = 57. You may assume the number of rings for each color given to the method will always greater than or equal to 0. Complete you method below. You do not have to write an entire program, just the method described. CS 305j Midterm 1 Fall 2006 6

7. Programming. 15 points. Write a method that prints out a String with a specified number of characters per line. The method is given the String and the number of characters to print per line and then prints out that many characters per line, until every character in the String has been printed out. You may assume that the number of characters in the given String is always a multiple of the given number of characters to print per line. For example if the String is "Isabelle" and the number of characters per line is 4, the output to the screen would be: Isab elle In this example the String "Isabelle" has 8 characters so the only valid characters per line would be 1, 2, 4, or 8. Note all characters are treated the same. For example if the given String was "The Texas Longhorns!" and the number of characters per line was 5 the output would be: The T exas Longh orns! Note, the second line looks like it has 4 characters, but it actually has 5; the last one is a space. In this example the String "The Texas Longhorns!" has 20 characters so the only valid characters per line would be 1, 2, 4, 5, 10, or 20. You may assume that the number of characters in the given String is always a multiple of the given number of characters to print per line. You will need to use the length() and charat() methods from the String class. Recall the charat method has one parameter, the index of the character to get from the String. The index of the first character is 0. Complete you method below or on the next page. You do not have to write an entire program, just the method described. There is more room on the next page if you need it. CS 305j Midterm 1 Fall 2006 7