Java Help

profilechrizlo
questions.pdf

1. What output is produced by the following code fragment?

int limit = 100, num1 = 15, num2 = 40; if (limit <= limit){ if (num1 == num2) System.out.println("lemon"); System.out.println("lime"); } System.out.println("grape");

2. What is wrong with the following code fragment?

count = 50; while (count >= 0){ System.out.println(count); count = count + 1; }

3. Design and implement an application that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side.

 Print an appropriate statement if all three of the numbers are the same, or if any two of the numbers are the same.

 Continue playing until the user chooses to stop.

4. Modify the Die class from Chapter 4 so that the setFaceValue method does nothing if the parameter is outside of the valid range of values.

5. Modify the Account class from Chapter 4 so that it performs validity checks on the deposit and withdraw operations.

 Specifically, don’t allow the deposit of a negative number or a withdrawal that exceeds the current balance.

 Print appropriate error messages if these problems occur.