Group Work - Remainder Operator (%)

From CS Awesome 2CC BY-NC-SA 4.0Original page

Java1 class period1 exerciseNot autograded

Files

README.mdDownload

Group Work - Remainder Operator (%)

Each coding exercise has its own folder. Open its .java file and press Run to try it.

It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home. This page is based on a POGIL activity from Helen Hu at that site.

Look at the expressions in the code above and the output. Then answer the following questions.

Exercise 1

Run the code to see what it prints.

Open the 01-mod-model-1 folder and run ModModl1.java. It is an example, so it has no tests.

Check your understanding: Review the code in 01-mod-model-1. What is the first number (n) such that n % 4 returns zero? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-which-returns-zero

Check your understanding: Review the code in 01-mod-model-1. What is the next number (n) (greater than 16) such that n % 4 returns zero? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-next-returns-zero

Going Beyond Remainder 4

Check your understanding: What is the first number from 1 to 10 that is evenly divisible by five (n % 5 returns 0)? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-return-zero-mod-five

Check your understanding: What is the last number from 1 to 10 that is evenly divisible by five (n % 5 returns 0)? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-return-zero-mod-five-last

Look Deeper

Look at the code above for the numbers such that n % 4 returns 1. How do these numbers differ from the ones that return zero?

Discuss this with your class, or answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-returns-one-sa

More Practice

Check your understanding: What is the number returned from 18 % 4? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-18-mod-4

Check your understanding: What is the number returned from 19 % 4? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-19-mod-4

Check your understanding: What is the number returned from 19 % 5? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-19-mod-5

Check your understanding: What is the number returned from 19 % 6? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-19-mod-6

Long Division with a Remainder

Consider how you did long division in elementary school where you determined what number goes evenly into another number and the remainder.

Mod ex

Check your understanding: What number is the remainder when you divide 79 by 5? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-79-mod-5

Dividing Evenly

Imagine if you were given candies to evenly divide amoung members of a group of four people. Follow kindergarten rules where every group member gets the same number of candies and the extras go back to the teacher.

Check your understanding: How many candies go back to the teacher when you are given 11 candies? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-11-mod-4

Check your understanding: How many candies go back to the teacher when you are given 2 candies? — answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-2-mod-4

Describe the Remainder (%) Operator

Describe what % does in your own words. Use complete sentences.

Discuss this with your class, or answer it on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/group-mod-practice.html#mod-describe-mod-sa

For teachers

Group Work - Remainder Operator (%)

Students read CSAwesome2's “Group Work - Remainder Operator (%)” in CS Room and work through its 1 Java coding exercise (examples, not graded).

  • Time: 1 class period
  • Tests: none

Goals

  • Practice for Unit 2: Selection and Iteration.

Before class

In class

  1. Students read README.md. Questions that need CS Awesome's interactive widgets link back to it.
  2. Students run the example in exercise 01 in its folder.

Exercises

FolderFileGradingTests
01-mod-model-1ModModl1.javaExample, not graded0