Skip to main content

Section 1.22 Coding Practice 1b (1.7-1.15)

Activity 1.22.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.

Activity 1.22.2.

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

Activity 1.22.3.

Given the Television class below, 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.

Activity 1.22.4.

The following 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.

Activity 1.22.5.

The following 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.

Activity 1.22.6.

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

Activity 1.22.7.

The following 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.

Activity 1.22.8.

The following code should replace lol in the message with laugh out loud and print the new message using indexOf and substring.
For more practice with Strings see problems at http://codingbat.com/java/String-1.
Here are some practice coding problems for Turtles.

Activity 1.22.9.

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

Activity 1.22.10.

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

Activity 1.22.11.

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

Activity 1.22.12.

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

Activity 1.22.13.

Finish the code below to have t1 draw something interesting.
You have attempted of activities on this page.