Your Turn
- Write program code to complete the provided tasks.
- Run the code in the Java Program to see if your code generates the desired result.
- Make necessary changes until you have satisfied the tasks.
Practice 1: Square Roots in Construction
An architect needs to find the side length of a square plt with an area of 225 square meters.
- Which
Math
class method helps find the side length?
- Write an expression to find the side length.
- Try this in the Java Playground.
Practice 2: Game Randomization
A game randomly spawns coins for the player to collect. There is a 1 in 10 chance to generate a coin.
- Write an expression to generate a random integer between 1 and 10, inclusively.
- Try this in the Java Playground.
Practice 3: Elevation Difference
Between two cities, one is 245m above sea level and the other is 123m below.
- Which
Math
class method would you use to find the total difference in elevation?
- Write an expression to find the total difference in elevation.
- Try this in the Java Playground.
Practice 4: Rounding Up
You need to buy tiles for a bathroom floor that measures size
square meters, but tiles are sold by the square meter.
- Which
Math
class method would you use to find how many tiles you should buy?
- Write an expression to find the number of tiles you should buy.
- Try this in the Java Playground.
Practice 5: Speed Records
Two runners complete a race, determine the faster racer.
- Which
Math
class method would you use to determine which racer is faster? Faster means lower time.
- Write an expression to find the time of the faster racer.
- Try this in the Java Playground.
Practice 6: Random Expression Practice
Write random expressions for each prompt.
Resources