Toggle Code Practice 1a (1.1-1.6)
From CS Awesome 2CC BY-NC-SA 4.0Original page
Java2 class periods14 exercises17 graded tests
Files
Toggle Code Practice 1a (1.1-1.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.
For each of the coding problems below, write your own solution.
Exercise 1
Write code that prints Maria’s first name on one line and her last name on the next line.
Open the
01-u1a-toggle1folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 2
Write code that prints the poem Roses are red Violets are blue Sugar is sweet And so are you with 1 sentence on each line.
Open the
02-u1a-toggle2folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 3
Write code that prints Marcus’s name on one line and his favorite color (Blue) on the next line.
Open the
03-u1a-toggle3folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 4
Write code that figures out the cost for each shirt if you buy 2 and get the third free and they are originally $45 each. Make sure your answer is a double.
Open the
04-u1a-toggle4folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 5
Write code that figures out the cost per person for a dinner including the tip. Assume the bill was $89.23, there are three people, and the tip should be 20%. Make sure your answer is a double.
Open the
05-u1a-toggle5folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 6
Write code that calculates and prints the number of seconds in 5 days.
Open the
06-u1a-toggle6folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 7
Write code that calculates and prints the number of months it would take you to save $500 if you make $50 a week. Make sure your answer is a double.
Open the
07-u1a-toggle7folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 8
Write code that prints the name on one line followed by the age on the next line. Your output should look like Your name is Layla and Your age is 16.
Open the
08-u1a-toggle8folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 9
Write code that prints the name on one line and the favorite food on the next line. Your output should look like:
Your name is Julian
Your favorite food is chicken wings
Open the
09-u1a-toggle9folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 10
Write code that calculates and prints the cost of a trip that is 200 miles when the price of gas is 2.20 and the miles per gallon is 42. Make sure your answer is a double.
Open the
10-u1a-toggle10folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 11
Write code that calculates how many miles you can go on half a tank of gas if the miles per gallon is 26 and your tank holds 15 gallons.
Open the
11-u1a-toggle11folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 12
Write code that calculates and prints how many chicken wings you can buy with $3.50 if the wings are $.60 each. Make sure your answer is an integer.
Open the
12-u1a-toggle12folder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
Exercise 13
Write code that calculates how much you will have to pay for an item that is 60 percent off the original price of $52.99.
Open the
13-u1a-toggle13folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 14
Write code that calculates and prints how much the per item costs is for shorts that are buy 2 and get the third free. The shorts are $39.99 each.
Open the
14-u1a-toggle14folder and editTest1.java. Press Run to try it; Run Tests checks it (3 tests).
For teachers
Toggle Code Practice 1a (1.1-1.6)
Students read CSAwesome2's “Toggle Code Practice 1a (1.1-1.6)” in CS Room and work through its 14 Java coding exercises.
- Time: 2 class periods
- Tests: 17 in 14 graded exercises, set up for you when you import the lesson
Goals
- Practice for topics 1.1–1.6: 1.1 Introduction to Algorithms, Programming, and Compilers, 1.2 Variables and Data Types, 1.3 Expressions and Output, 1.4 Assignment and Input, 1.5 Casting and Ranges of Values, 1.6 Compound Assignment Operators.
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/unit1a-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–14, 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-u1a-toggle1 | Test1.java | Autograded | 1 |
02-u1a-toggle2 | Test1.java | Autograded | 1 |
03-u1a-toggle3 | Test1.java | Autograded | 1 |
04-u1a-toggle4 | Test1.java | Autograded | 1 |
05-u1a-toggle5 | Test1.java | Autograded | 1 |
06-u1a-toggle6 | Test1.java | Autograded | 1 |
07-u1a-toggle7 | Test1.java | Autograded | 1 |
08-u1a-toggle8 | Test1.java | Autograded | 1 |
09-u1a-toggle9 | Test1.java | Autograded | 1 |
10-u1a-toggle10 | Test1.java | Autograded | 1 |
11-u1a-toggle11 | Test1.java | Autograded | 1 |
12-u1a-toggle12 | Test1.java | Autograded | 2 |
13-u1a-toggle13 | Test1.java | Autograded | 1 |
14-u1a-toggle14 | Test1.java | Autograded | 3 |
Teachers can download a reference solution after signing in.