{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm1Fall02

# midterm1Fall02 - Points off 1 2 3 4 Admin Total off Net...

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

Points off 1 2 3 4 Admin Total off Net Score CS 307 – Midterm 1 – Fall 2002 Your Name____________________________________ Last 4 digits of SSN / Student ID ______________ Section Leaders Name ___________________________ Instructions: 1. There are 4 questions on this test. 2. You will have 3 hours to complete the test. 3. You may not use a calculator. 4. When code is required, write Java code. 5. Please make your answers legible. 6. The style guide is not in effect, except as noted. 7. Unless noted on the question, you may not use any of the classes or methods from the Java standard library. You may use native arrays 1. (2 points each, 30 points total) Java Mechanics. For all parts, what is the output of the code fragment? Write your answer on the line provided. Consider each piece of code in isolation. If the code would cause an error, answer "syntax error" or "runtime error" depending on what type of error it would be. A. int xa = 12; int ya = 5; double aa = xa / ya + 1.5; System.out.println( aa ); ____________________________________________ B. int xb = 37; int yb = 5; int zb = xb % yb + xb / yb; System.out.println( zb ); _________________________________________________ CS 307 – Midterm 1 – Fall 2002 1

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

View Full Document
For parts C – J consider the following class: public class Ellipse { private int iMyX; private int iMyY; private int iMyXDistance; private int iMyYDistance; public Ellipse(int x, int y, int xDistance, int yDistance) { iMyX = x; iMyY = y; iMyXDistance = xDistance; iMyYDistance = yDistance; } public void setX(int x) { iMyX = x; } public void setY(int y) { iMyY = y; } public int getX() { return iMyX; } public int getY() { return iMyY; } public String toString() { return iMyX + " " + iMyY + " " + iMyXDistance + " " + iMyYDistance; } } CS 307 – Midterm 1 – Fall 2002 2
C. public class EllipseUser { public void tree(Ellipse e1, Ellipse e2) { int tempX = e1.getX(); int tempY = e1.getY(); e1.setX( e2.getX() ); e1.setY( e2.getY() ); e2.setX( tempX ); e2.setY( tempY ); } public void cardinal() { Ellipse ep1 = new Ellipse(2, 4, 6, 8); Ellipse ep2 = new Ellipse(5, 10, 15, 20); ep1.setX(12); tree(ep1, ep2); System.out.println( ep1.toString() ); System.out.println( ep2.toString() ); } } What is the output when method cardinal in class EllipseUser is called? D. public class EllipseUser2 { public void wave(Ellipse e1) { e1.setY( 50 ); e1 = new Ellipse(100, 200, 250, 250); e1.setX( 12 ); } public void pack() { Ellipse ep1 = new Ellipse(10, 20, 30, 35); ep1.setY(40); System.out.println( ep1.toString() ); } } What is the output when method pack in class EllipseUser2 is called? ___________________________________________________________ CS 307 – Midterm 1 – Fall 2002 3

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

View Full Document
E. public class EllipseUser3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

midterm1Fall02 - Points off 1 2 3 4 Admin Total off Net...

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

View Full Document
Ask a homework question - tutors are online