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

README.mdDownload

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-toggle1 folder and edit Test1.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-toggle2 folder and edit Test1.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-toggle3 folder and edit Test1.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-toggle4 folder and edit Test1.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-toggle5 folder and edit Test1.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-toggle6 folder and edit Test1.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-toggle7 folder and edit Test1.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-toggle8 folder and edit Test1.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-toggle9 folder and edit Test1.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-toggle10 folder and edit Test1.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-toggle11 folder and edit Test1.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-toggle12 folder and edit Test1.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-toggle13 folder and edit Test1.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-toggle14 folder and edit Test1.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

Before class

In class

  1. Students read README.md.
  2. Students do exercises 01–14, each in its own folder, pressing Run to try their code.
  3. 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

FolderFileGradingTests
01-u1a-toggle1Test1.javaAutograded1
02-u1a-toggle2Test1.javaAutograded1
03-u1a-toggle3Test1.javaAutograded1
04-u1a-toggle4Test1.javaAutograded1
05-u1a-toggle5Test1.javaAutograded1
06-u1a-toggle6Test1.javaAutograded1
07-u1a-toggle7Test1.javaAutograded1
08-u1a-toggle8Test1.javaAutograded1
09-u1a-toggle9Test1.javaAutograded1
10-u1a-toggle10Test1.javaAutograded1
11-u1a-toggle11Test1.javaAutograded1
12-u1a-toggle12Test1.javaAutograded2
13-u1a-toggle13Test1.javaAutograded1
14-u1a-toggle14Test1.javaAutograded3

Teachers can download a reference solution after signing in.