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

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

View Full Document Right Arrow Icon
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; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

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 Right Arrow Icon
Ask a homework question - tutors are online