CS 312 Midterm 1 Spring 2013

Similar documents
CS 312 Midterm 1 Spring 2013

CS 305j Midterm 1 Fall 2006

CS 305j Midterm 1 Fall 2007

CS 305j Midterm 1 Fall 2008

CS 312 Exam 1 Fall KG Kris Megan Roman Sonika

CS 312 Midterm 2 Fall 2013

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

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

TWO-DIMENSIONAL FIGURES

Building Java Programs

Topic 8 graphics. -mgrimes, Graphics problem report 134

Fall_2010_M1_SuggestedSolutioAndGradingCrit.txt 10/8/2010

Garfield AP CS. Graphics

Building Java Programs

Building Java Programs

JAVA OPERATORS GENERAL

CS314 Spring 2014 Midterm 1 Solution and Grading Criteria.

Building Java Programs

CS314 Fall 2011 Midterm 1 Solution and Grading Criteria.

Topic 8 Graphics. Margaret Hamilton

1. Answer as shown or -2 unless question allows partial credit. No points off for differences in spacing, capitalization, commas, and braces

1. Answer as shown or -1 unless question allows partial credit. No points off for minor differences in spacing, capitalization, commas, and braces

CS 312 Midterm 2 Fall Jose Stas Aaron

CS314 Fall 2012 Midterm 1 Solution and Grading Criteria.

1. Answer as shown or -1 unless question allows partial credit. No points off for minor differences in spacing, capitalization, commas, and braces

I. True/False: (2 points each)

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

1. Answer as shown or -2 unless question allows partial credit. No points off for differences in spacing, capitalization, commas, and braces

Selenium Class 9 - Java Operators

Chapter 6 Methods. Dr. Hikmat Jaber

CS 101 Spring 2007 Midterm 2 Name: ID:

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Using Graphics. Building Java Programs Supplement 3G

I. True/False: (2 points each)

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

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.

CS314 Exam 1 - Fall Suggested Solution and Criteria 1

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

D. Do inorder traversal on tree, values in ascending order, no repeats.

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

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

1. Answer as shown or -1 unless question allows partial credit. No points off for minor differences in spacing, capitalization, commas, and braces.

I. True/False: (2 points each)

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

CS115 Principles of Computer Science

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

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

Building Java Programs

CONDITIONAL EXECUTION

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

Assignment 2. Application Development

Chapter 5 Methods. Modifier returnvaluetype methodname(list of parameters) { // method body; }

Appendix F: Java Graphics

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

Building Java Programs

Key Java Simple Data Types

CS314 Exam 1 - Spring Suggested Solution and Criteria 1

The way I feel about music is that there is no right and wrong. Only true and false. Fiona Apple. true false false

Appendix F: Java Graphics

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Java Simple Data Types

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

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

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet)

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

COMP102: Test 1 Model Solutions

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

Prof. Navrati Saxena TA: Rochak Sachan

Java Simple Data Types

Exam Percentage: / 55 = %

CSC 1051 Data Structures and Algorithms I

Topic 12 more if/else, cumulative algorithms, printf

CS314 Exam 1 - Fall Suggested Solution and Criteria 1

CS110: PROGRAMMING LANGUAGE I

Practice Midterm 1. Problem Points Score TOTAL 50

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

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

The Math Class. Using various math class methods. Formatting the values.

Applets and the Graphics class

Operators Questions

Using Methods and Parameters

Name CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam.

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

CMP 326 Midterm Fall 2015

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

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

CS 139 Practice Midterm Questions #2

CS 307 Midterm 1 Fall 2007

Midterm Exam CS 251, Intermediate Programming March 12, 2014

16. Give a detailed algorithm for making a peanut butter and jelly sandwich.

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

1. Expressions - 1 point each. -1 for missing or extra " OR.0. differences in capitalization of true and false okay. No limit on points off.

CSC 240 Computer Science III Spring 2018 Midterm Exam. Name

Introduction to: Computers & Programming: Review prior to 1 st Midterm

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

Data Representation and Applets

CMPT-166: Sample Midterm

Transcription:

CS 312 Midterm 1 Spring 2013 Your Name KEY AND CRITERIA Problem Number Topic Points Possible 1 Expressions 11 2 Loop Evaluation 6 3 Method Tracing 10 4 Method Tracing 3 5 Writing Methods 5 6 Tracing Graphics 5 7 Programming 10 8 Using Graphics 10 TOTAL POINTS OFF: SCORE OUT OF 60: Points Off Grading Acronyms: NAP = No Answer Provided LE = Logic Error GCE = Gross Conceptual Error, based on answer did not understand question. OBOE = Off By One Error BOD = Benefit Of the Doubt GACK = poor style or approach, but no points off CS 312 Midterm 1 Spring 2013 - Key And Criteria 1

1. Expressions. 1 point each, 11 points total. For each Java expression in the left hand column, indicate its value in the right hand column. You must show a value of the appropriate type. For example, 7.0 rather than 7 for a double and "7" instead of 7 for a String. Answers that do not indicate the data type correctly are wrong. Wrong if missing quotes for Strings or decimal for doubles A. 12 + "CS" + "\"" + 1 + "E" "12CS"1E" B. 82617 / 1000 % 10 + 3 * 10 32 C. 1.5 + 6 / 4 + 2.5 5.0 D. 117 % 100 + 2 * 100 * 3 % 50 17 E. 29 / 4 / 2.0 + 18 / 5 + 1.5 8.0 F. "UT" + "POP" + 3 * 5 "UTPOP15" G. 3 * 2 + "C++" + 2 + 1 "6C++21" H. 3 + 4 / (((double) 2) / 20) 43.0 I. 1.5 * 3 / 2 + 2 * 3 8.25 J. The three Math methods(ceil, floor, and abs) in the next expression all return doubles. Math.ceil(1.02) + Math.floor(2.4) + Math.abs(-1.5) 5.5 K. ((int) 15.6) * 3 + 2 * 3 51 CS 312 Midterm 1 Spring 2013 - Key And Criteria 2

2. Loops Simulation. 6 points total, 2 points each. Consider the following method: public static void loop(int m, int p) { final int LIMIT = m * p; int temp = 0; for(int i = 1; i <= LIMIT; i++) { temp++; temp += m; p += 2; System.out.print(m + " " + p + " " + temp); What is printed out by the following method calls? -1 for each wrong number in order up to -2 per part Method Call Output to screen loop(-1, 3); -1 3 0 ------------------------------------------------------------------ loop(1, 4); 1 12 8 ------------------------------------------------------------------ loop(-2, -2); -2 6-4 ------------------------------------------------------------------ CS 312 Midterm 1 Spring 2013 - Key And Criteria 3

3. Method Tracing and Parameters Simulation. (10 points) Consider the following program: public class ParameterQuestion { public static void main(string[] args) { int a = 3; int b = first(a); System.out.println("A: " + a + " " + b); int x = 2; int y = 3; int z = second(x, y); System.out.println("B: " +x+ " " +y+ " " + z); a = third(-2, 3); System.out.println("C: " + a); a = 4; b = a / 2; int c = fourth(a, b); System.out.println("D: " +a+ " " +b+ " " + c); public static int first(int a) { a += 2; return a * 2; List output of program here: A: 3 10 B: 2 3 18 E: 3-2 C: 3 D: 4 2 18-1 per wrong number per line up to -2 per line -1 if wrong order on letters public static int second(int a, int b) { a = first(a); b = first(b); return a + b; public static int third(int a, int b) { int temp = a; a = b; b = temp; System.out.println("E: " + a + " " + b); return a; public static int fourth(int a, int b) { int y = second(b, a); return y - b; In the box to the above list the output produced when the program runs. List the output in the order it will appear on the screen when the program runs. CS 312 Midterm 1 Spring 2013 - Key And Criteria 4

4. Method Tracing. 3 points. What is output when the following program is run? public class MethodTrace { public static void main(string[] args) { int x = 5; int y = 10; System.out.println( toy(x) + " " + x + " " + toy(y)); public static int toy(int x) { x = x * x; System.out.print(x); return x; -1 for each value out of order or wrong. OUTPUT: 2510025 5 100 5. (5 points) Write a method that calculates and returns a student's GPA given the number of A's, B's, C's, D's, and F's the student has earned in classes. The number of each letter grade earned (A, B, C, D, and F) are sent as parameters to the method. Assume every class the student takes is worth 3 credits. A's are worth 4 grade points, B's are worth 3 grade points, C's are worth 2 grade points, D's are worth 1 grade point, and F's are worth 0 grade points. For example, given a student with 3 A's, 4 B's, 1 C, 0 D's, and 2 F's the method returns a GPA of 2.6. public static double getgpa(int a, int b, int c, int d, int f) { int totalclasses = a + b + c + d + f; int points = a * 4 + b * 3 + c * 2 + d; return ((double) points) / totalclasses; header: 1 point calculate total classes: 1 point calculate grade points: 1 point return value: 1 point floating point division: 1 point hard coding number of each grade: - 4 CS 312 Midterm 1 Spring 2013 - Key And Criteria 5

6. Tracing Graphics Programs. 5 points. Sketch the drawing panel window that is produced when the following program when is run. Do not draw the title bar. import java.awt.*; public class Draw { public static final int SIZE = 400; public static void main(string[] args) { DrawingPanel p = new DrawingPanel(SIZE, SIZE); Graphics g = p.getgraphics(); int part = SIZE / 4; // parameters on drawrect and filloval are x, y, width, height g.drawrect(part, 0, part, SIZE); g.drawrect(0, part, SIZE, part); g.setcolor(color.red); g.filloval(part, part, SIZE / 2, SIZE / 2); Sketch the DrawingPanel produced by the program in the box to the right. Indicate the color with a label if it is not black. Recall the origin is at the top left corner and y increases down the panel, not up. red 2 rectangles: 1 point 1 circle: 1 point circle filled and labeled red: 1 point rectangles approximately correct position and size: 1 point circle approximately correct position and size: 1 point CS 312 Midterm 1 Spring 2013 - Key And Criteria 6

7. Programming. 10 points. Write a method that prints out the volume of a box for various values of length, width, and height. The method shall have 3 parameters for the maximum length, width, and height. Print out all volumes of the box as the length, width, and height, vary from 1 to the maximum value. For example, given a maximum length of 2, a maximum width of 3, and a maximum height of 2 your method shall produce the following output: LEN: 1 WID: 1 HT: 1 VOL: 1 LEN: 1 WID: 1 HT: 2 VOL: 2 LEN: 1 WID: 2 HT: 1 VOL: 2 LEN: 1 WID: 2 HT: 2 VOL: 4 LEN: 1 WID: 3 HT: 1 VOL: 3 LEN: 1 WID: 3 HT: 2 VOL: 6 LEN: 2 WID: 1 HT: 1 VOL: 2 LEN: 2 WID: 1 HT: 2 VOL: 4 LEN: 2 WID: 2 HT: 1 VOL: 4 LEN: 2 WID: 2 HT: 2 VOL: 8 LEN: 2 WID: 3 HT: 1 VOL: 6 LEN: 2 WID: 3 HT: 2 VOL: 12 public static void printvolumes(int ml, int mw, int mh) { for(int len = 1; len <= ml; len++) { for(int wid = 1; wid <= mw; wid++) { for(int ht = 1; ht <= mh; ht++) { int volume = len * wid * ht; System.out.println("LEN: " + len + " WID: " + wid + " HT: " + ht + " VOL: " + volume); header: 1 point parameters: 1 point 3 loops: 1 points loops nested correctly: 3 points correct limits on loops, use of parameters: 1 point calculate volume correctly inside nested loop: 2 point (must be in triply nested loop println correct inside nested loop: 1 points CS 312 Midterm 1 Spring 2013 - Key And Criteria 7

8. Graphics Programming. 10 Points. Complete a method to produce the following output. The Graphics object for the DrawingPanel is sent to the method as a parameter as well as the size of the DrawingPanel. Assume the DrawingPanel is square with length and width equal to the size parameter. A given oval has the same width and height. (They are circles.) The width and height of each successive circle is half of the previous circle. Each successive circle is drawn in the lower right quadrant of the previous circle. The method always draws 5 circles. Assume the color of the Graphics object has already been set to Color.BLACK. public static void drawcircles(graphics g, int size) { int coord = 0; int width = size; for(int i = 1; i <= 5; i++) { g.drawoval(coord, coord, width, width); width = width / 2; coord += width; header with parameters correct: 2 points call drawoval correct: 2 points draws 5 circles total: 2 points (-1 on width / height not necessary) draw circles in correct positions: 2 points draw circles of correct sizes: 2 points create new DrawingPanel: -1 hard coding the 5 ovals is okay if math correct. CS 312 Midterm 1 Spring 2013 - Key And Criteria 8