Coding Practice 1a (1.1-1.6)
From CS Awesome 2CC BY-NC-SA 4.0Original page
Java2 class periods16 exercises25 graded tests
Files
Coding 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.
Exercise 1
The code should print “Mary’s favorite color is blue”. However, the code has errors. Fix the code so that it compiles and runs correctly.
Open the
01-u1afix1folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 2
The code should print “Gabby’s favorite sport is soccer”. However, the code has errors. Fix the code so that it compiles and runs correctly.
Open the
02-u1afix2folder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 3
The code should print Your name is Carly and your favorite color is red. Finish the code so that it prints the output correctly using the variables provided.
Open the
03-u1afix3folder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
Exercise 4
Finish the code so that it prints Your name is Justin and your age is 16 using the variables provided.
Open the
04-u1afix4folder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
Exercise 5
Write the code to print Julian's favorite color is green. His favorite food is pizza. using the variables provided.
Open the
05-u1afix5folder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
Exercise 6
Finish the code to print your favorite animal and food.
Open the
06-u1afix6folder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests). Its tests check your code, not what it prints: “Code prints animal variable”, “Code prints food variable”.
Exercise 7
Finish the code to print your favorite movie and book.
Open the
07-u1aconcatfolder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests). Its tests check your code, not what it prints: “Code prints movie variable”, “Code prints book variable”.
Exercise 8
The code should calculate the cost of a trip that is 300 miles if gas is $2.50 a gallon and your car gets 30 miles per gallon. However, the code has syntax errors, like missing semicolons, wrong case on names, or unmatched " or (. Fix the code so that it compiles and runs correctly.
Open the
08-u1acostsfolder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 9
The code should calculate the body mass index (BMI) for someone who is 5 feet tall and weighs 110 pounds. However, the code has syntax errors, like missing semicolons, wrong case on names, or unmatched " or (. Fix the code so that it compiles and runs correctly.
Open the
09-u1abmifolder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 10
The code should calculate the number of miles that you can drive when you have $8.00 and the price of gas is 2.35 and the car gets 40 miles per gallon. However, the code has errors. Fix the code so that it compiles and runs correctly.
Open the
10-u1amilesfolder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 11
The code should calculate the cost of an item that is on clearance (70% off) when you also have a coupon for an additional 20% off the clearance price. However, the code has errors. Fix the code so that it compiles and runs correctly.
Open the
11-u1aclearancefolder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 12
The code should calculate the number of whole days in 320893 seconds. However, the code has errors. Fix the code so that it compiles and runs correctly.
Open the
12-u1adaysfolder and editTest1.java. Press Run to try it; Run Tests checks it (1 test).
Exercise 13
Complete the code to calculate and print how many months it will take to save $200 if you earn $20 a week.
Open the
13-u1amonthsfolder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
Exercise 14
Write the code to calculate the number of miles you can drive if you have a 10 gallon gas tank and are down to a quarter of a tank of gas and your car gets 32 miles per gallon.
Open the
14-u1snumMilesfolder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
Exercise 15
Write the code to calculate the number of seconds in 3 days. Remember that there are 60 seconds in a minute and 60 minutes in an hour and 24 hours in a day.
Open the
15-u1anumSecsfolder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
Exercise 16
Write the code to print the number of chicken wings you can buy if you have $4.50 and they cost $0.75 each. Remember that you can’t buy part of a wing.
Open the
16-u1awingsfolder and editTest1.java. Press Run to try it; Run Tests checks it (2 tests).
For teachers
Coding Practice 1a (1.1-1.6)
Students read CSAwesome2's “Coding Practice 1a (1.1-1.6)” in CS Room and work through its 16 Java coding exercises.
- Time: 2 class periods
- Tests: 25 in 16 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-coding.html
- CS Awesome's own teacher materials: the CS Awesome teacher site
In class
- Students read
README.md. - Students do exercises 01–16, 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-u1afix1 | Test1.java | Autograded | 1 |
02-u1afix2 | Test1.java | Autograded | 1 |
03-u1afix3 | Test1.java | Autograded | 2 |
04-u1afix4 | Test1.java | Autograded | 2 |
05-u1afix5 | Test1.java | Autograded | 2 |
06-u1afix6 | Test1.java | Checks code text only | 2 |
07-u1aconcat | Test1.java | Checks code text only | 2 |
08-u1acosts | Test1.java | Autograded | 1 |
09-u1abmi | Test1.java | Autograded | 1 |
10-u1amiles | Test1.java | Autograded | 1 |
11-u1aclearance | Test1.java | Autograded | 1 |
12-u1adays | Test1.java | Autograded | 1 |
13-u1amonths | Test1.java | Autograded | 2 |
14-u1snumMiles | Test1.java | Autograded | 2 |
15-u1anumSecs | Test1.java | Autograded | 2 |
16-u1awings | Test1.java | Autograded | 2 |
Teachers can download a reference solution after signing in.