# Coding Practice 1b (1.7-1.15)

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

Write the code to print a random number from 1 to 100. You can use `Math.random()` to get a value between 0 and not quite 1.

> Open the `01-exRandom100` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (3 tests). Its tests check your code, not what it prints: “random number up to 100”, “random number starting at 1”, “casting to int”.

## Exercise 2

Given the Circle class, use its constructor to create a circle of radius 5.0 and then print out its area using its getArea method.

> Open the `02-circleMethods` folder and edit `Circle.java`. Press **Run** to try it; **Run Tests** checks it (3 tests).

## Exercise 3

Given the Television class, use its constructor to create a Television object with the brand `Sony` and price `499.99`. Then print out its brand and price. Finally, set the number of pixels to `1080` and print it out.

> Open the `03-tvMethods` folder and edit `TestTelevision.java`. Press **Run** to try it; **Run Tests** checks it (5 tests).

## Exercise 4

The code should get the first letter of the first name, middle name, and last name and append (concatenate) them together and then return them all in lowercase. However, the code has errors. Fix the code so that it compiles and runs correctly.

> Open the `04-exFirstLetter` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 5

The code should print the first 3 letters of the string `message` all in lowercase letters. However, the code has errors. Fix the errors so that the code runs as intended.

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

## Exercise 6

The code starts with `String name1 = "ALEX";` and should print `Alex`. Use the `toLowerCase` and `substring` methods to do this task.

> Open the `06-exLower` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 7

The code should remove the word “very ” (and following space) from the message and print the new message. You can use `indexOf` to find the position of a substring in your string. You can use `substring` to create a new string removing the word.

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

## Exercise 8

The code should replace `lol` in the message with `laugh out loud` and print the new message using indexOf and substring.

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

## More practice

For more practice with Strings see problems at [http://codingbat.com/java/String-1](http://codingbat.com/java/String-1).

- [http://codingbat.com/prob/p161056](http://codingbat.com/prob/p161056)
- [http://codingbat.com/prob/p147483](http://codingbat.com/prob/p147483)
- [http://codingbat.com/prob/p108853](http://codingbat.com/prob/p108853)
- [http://codingbat.com/prob/p130896](http://codingbat.com/prob/p130896)
- [http://codingbat.com/prob/p130781](http://codingbat.com/prob/p130781)

Here are some practice coding problems for Turtles.

## Exercise 9

Finish the code to have `t1` draw a triangle where all of the sides are length 50.

> Open the `09-Turtle-eoc-triangle-ac` folder and edit `TurtleTest.java`. This one is not graded, so check it yourself. It draws pictures: **Run** saves the drawing as an image in its folder.

## Exercise 10

Finish the code to have `t1` draw a rectangle. The vertical sides should be length 50 and the horizontal length 100.

> Open the `10-Turtle-eoc-rect-ac` folder and edit `TurtleTest.java`. This one is not graded, so check it yourself. It draws pictures: **Run** saves the drawing as an image in its folder.

## Exercise 11

Finish the code to have `t1` draw the number seven.

> Open the `11-Turtle-eoc-draw-seven-ac` folder and edit `TurtleTest.java`. This one is not graded, so check it yourself. It draws pictures: **Run** saves the drawing as an image in its folder.

## Exercise 12

Finish the code to have `t1` draw the number four.

> Open the `12-Turtle-eoc-draw-four-ac` folder and edit `TurtleTest.java`. This one is not graded, so check it yourself. It draws pictures: **Run** saves the drawing as an image in its folder.

## Exercise 13

Finish the code to have `t1` draw something interesting.

> Open the `13-Turtle-eoc-draw-interesting-ac` folder and edit `TurtleTest.java`. This one is not graded, so check it yourself. It draws pictures: **Run** saves the drawing as an image in its folder.
