# Selection Coding Practice (2.1-2.6)

Each coding exercise has its own folder. Open its `.java` file and press **Run** to try it. **Run Tests** checks every graded exercise in this lesson at once.

## Exercise 1

The code should print `x is greater than 0`. However, the code has errors. Fix the code so that it compiles and runs correctly.

> Open the `01-ifpractice1` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (1 test).

## Exercise 2

The code should check your guess against the answer and print that it is too low, correct, or too high. However, the code has errors. Fix the code so that it compiles and runs correctly.

> Open the `02-ifpractice2` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (1 test).

## Exercise 3

The code should print “You can go out” if you have done your homework and cleaned your room. However, the code has errors. Fix the code so that it compiles and runs correctly.

> Open the `03-ifpractice3` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (1 test).

## Exercise 4

The code should print if x is in the range of 0 to 10 (including 0 and 10). However, the code has errors. Fix the errors so that the code runs as intended.

> Open the `04-ifpractice4` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (1 test).

## Exercise 5

The code should print if x is less than 0, equal to 0, or greater than 0. Finish it to work correctly.

> Open the `05-ifpractice5` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (3 tests).

## Exercise 6

Finish the code so that it prints `You can go out` if you have a ride or if you can walk and otherwise prints `You can't go out`. Use a logical or to create a complex conditional.

> Open the `06-ifpractice6` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (4 tests). Its tests check your code, not what it prints: “print statement You can go out”, “print statement You can't go out”, “or”, “Code has been changed”.

## Exercise 7

Finish the code to print you can go out if you don’t have homework and you have done the dishes.

> Open the `07-ifpractice7` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (4 tests). Its tests check your code, not what it prints: “print statement You can go out”, “and”, “not”, “Code has been changed”.

## Exercise 8

Finish the code so that it prints `You have a fever` if your temperature is above 100 and otherwise prints `You don't have a fever`.

> Open the `08-ifpractice8` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (4 tests). Its tests check your code, not what it prints: “print statement You have a fever”, “print statement You don't have a fever”, “if statement for temp greater than 100”, “Code has been changed”.

## Exercise 9

Finish the code to print `It is freezing` if the temperature is below 30, `It is cold` if it is below 50, `It is nice out` if it is below 90, or `It is hot` using nested if else statements.

> Open the `09-ifpractice9` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (5 tests).

## Exercise 10

Finish the code to print your grade based on your score. The score is an A if you scored 92 or higher, a B if you scored 82 to 91, a C if you scored 72 to 81, a D if you scored a 62 to 71, or an E.

> Open the `10-ifpractice10` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (10 tests). Its tests check your code, not what it prints: “Code has been changed”, “print statement - A”, “print statement - B”, “print statement - C”, “print statement - D”, “print statement - E”, “if you scored 92 or higher”, “else if you scored 82 or higher”, “else if you scored 72 or higher”, “else if you scored 62 or higher”.

## More practice

For more practice with conditionals, and especially complex conditionals, go to [http://codingbat.com/java/Logic-1](http://codingbat.com/java/Logic-1) and [http://codingbat.com/java/Logic-2](http://codingbat.com/java/Logic-2)

In particular we recommend solving the following problems

- [http://codingbat.com/prob/p118290](http://codingbat.com/prob/p118290)
- [http://codingbat.com/prob/p183071](http://codingbat.com/prob/p183071)
- [http://codingbat.com/prob/p110973](http://codingbat.com/prob/p110973)
- [http://codingbat.com/prob/p103360](http://codingbat.com/prob/p103360)
- [http://codingbat.com/prob/p169213](http://codingbat.com/prob/p169213)
- [http://codingbat.com/prob/p178728](http://codingbat.com/prob/p178728)
- [http://codingbat.com/prob/p115233](http://codingbat.com/prob/p115233)
