Toggle Code Practice 1b (1.7-1.15)
From CS Awesome 2CC BY-NC-SA 4.0Original page
Java1 class period6 exercises12 graded tests
Files
Toggle Code 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.
For each of the coding problems below, write your own solution.
Exercise 1
Write code that prints a random number from 1 to 50.
Open the
01-u1b-toggle1folder and editTest1.java. Press Run to try it; Run Tests checks it (5 tests).
Exercise 2
Write code that prints the first 2 characters of the message followed by the last 2 characters of the message using the appropriate String methods.
Open the
02-u1b-toggle2folder and editTest1.java. Press Run to try it; Run Tests checks it (3 tests).
Exercise 3
Write code that prints the first letters in first, middle, and last in lowercase letters using the appropriate String methods.
Open the
03-u1b-toggle3folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 4
Write code that prints the message in all uppercase letters using the appropriate String methods.
Open the
04-u1b-toggle4folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 5
Write code that prints the first 3 letters of the message in uppercase letters using the appropriate String methods.
Open the
05-u1b-toggle5folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 6
Write code that print the part of the message starting with the word “nice” using the appropriate String methods.
Open the
06-u1b-toggle6folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
For teachers
Toggle Code Practice 1b (1.7-1.15)
Students read CSAwesome2's “Toggle Code Practice 1b (1.7-1.15)” in CS Room and work through its 6 Java coding exercises.
- Time: 1 class period
- Tests: 12 in 6 graded exercises, set up for you when you import the lesson
Goals
- Practice for topics 1.7–1.15: 1.7 APIs and Libraries, 1.8 Documentation with Comments and Preconditions, 1.9 Method Signatures, 1.10 Calling Class Methods, 1.11 Using the Math Class, 1.12 Objects - Instances of Classes, 1.13 Creating and Initializing Objects: Constructors, 1.14 Calling Instance Methods, 1.15 Strings.
Before class
- Import the lesson into your class from the Lessons page, or with New assignment → Use a lesson. It arrives as a draft with its tests already set up.
- Publish it.
- The original page is on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/unit1b-practice-toggle-code.html
- CS Awesome's own teacher materials: the CS Awesome teacher site
In class
- Students read
README.md. - Students do exercises 01–06, each in its own folder, pressing Run to try their code.
- Run Tests checks every graded exercise at once; scores appear in the Gradebook. Grading uses your copy of the tests, so a student who edits theirs does not change the grade.
Exercises
| Folder | File | Grading | Tests |
|---|---|---|---|
01-u1b-toggle1 | Test1.java | Autograded | 5 |
02-u1b-toggle2 | Test1.java | Autograded | 3 |
03-u1b-toggle3 | Test1.java | Autograded | 1 |
04-u1b-toggle4 | Test1.java | Autograded | 1 |
05-u1b-toggle5 | Test1.java | Autograded | 1 |
06-u1b-toggle6 | Test1.java | Autograded | 1 |
Teachers can download a reference solution after signing in.