test1s10short

# test1s10short - CompSci 6 PROBLEM 1 Test 1(What is put...

This preview shows pages 1–4. Sign up to view the full content.

CompSci 6 Test 1 Spring 2010 PROBLEM 1 : ( What is put out? (30 points) ) A. (14 pts) List the output for the following code. int x = 5; double y = 2.0; int z = 3; String phrase = "Will Durham get 54 inches of snow?"; System.out.println("x/z = " + x/z); System.out.println("x/y = " + x/y); System.out.println("multiply " + x*z); System.out.println(Math.floor(6.7)); System.out.println(phrase.substring(6,9)); System.out.println(phrase.substring(phrase.indexOf("snow")+1)); int [] values = {4, 9, 12, 3, 6, 7}; for (int k = 1; k < values.length; k++) { if (values[k] > values[k-1] ) { System.out.print(values[k] + " "); } } System.out.println("done"); List OUTPUT here: B. (10 pts) Consider the following Mystery method. public int Mystery(Scanner in, String status) { int count = 0; while (in.hasNext()) { String name = in.next(); int age = in.nextInt(); String condition = in.next(); 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
{ count++; } } return count; } Answer the following questions about this code. 1. What is the return type for the method Mystery? 2. What are the names of the parameters in the Mystery method? 3. What are the types of the parameters in the Mystery method? 4. Assume the following data ﬁle has been bound to the Scanner in and is ready for reading. Maia 11 critical Sarah 15 stable Jeffrey 3 stable Quiang 8 critical Yu 11 critical What is the return value of the call Mystery(in, "critical") , where in is a Scanner bound to the above data ﬁle? 5. Explain what the method Mystery does. C. (6 pts) Consider the following graphics code. Remember that the top left corner of the drawing canvas is (0,0), the x values increase to the right and the y values increase as they go down. The method fillRect(int x, int y, int width, int height) draws a rectangle ﬁlled in with the current color and with its top left corner at (x,y). Point myCenter = new Point(50, 100); int width = 50; int height = 100; pen.setColor(java.awt.Color.red); pen.fillRect(myCenter.x, myCenter.y, width, height); 2
myCenter.x += 50; myCenter.y += 100; pen.setColor(java.awt.Color.green); pen.fillRect(myCenter.x, myCenter.y, width, height); Draw a picture showing what this code draws. Identify the color and top left x and y coordinates of any shape in your drawing. PROBLEM 2 :

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.
• Fall '09
• public int, Ski jumping, public int mystery, Simon Ammann Adam Malysz Simon Ammann Adam Malysz Adam Malysz Simon Ammann Simon Ammann Adam Malysz, current jump distance

{[ snackBarMessage ]}

### Page1 / 7

test1s10short - CompSci 6 PROBLEM 1 Test 1(What is put...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online