quiz6 - Name: _ Section: Dave's 15-100 M N O P February 25,...

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

1 Name: ____________________ Section: M N O P Dave's 15-100 February 25, 2009 Quiz 6 1. Complete the method factorial below. The factorial of n is defined as: n × ( n - 1) × ( n - 2) × . .. × 2 × 1 For example, factorial(5) should return 120, since 120 = 5 × 4 × 3 × 2 × 1. public static int factorial(int n) { int result; result = 1; while ( ______________________________ ) { result = ______________________________ ; n = ______________________________ ; } return result; }

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

View Full Document
2 2. Consider the Safe class defined below. public class Safe { private boolean locked; private int secretNumber; public Safe() { locked = true; secretNumber = 1 + (int)(Math.random() * 10); } public void unlock(int combo) { if (combo == 1234) locked = false; } public int getSecretNumber() { if ( ! locked) return secretNumber; else return 0; } } Every Safe conceals a "secret number" (a random integer from 1 to 10 chosen when the Safe is constructed). Complete the code below, so that it retrieves the newly created
This is the end of the preview. Sign up to access the rest of the document.

quiz6 - Name: _ Section: Dave's 15-100 M N O P February 25,...

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

View Full Document
Ask a homework question - tutors are online