Recursion in CodingBat Lab

Introduction

The goal of today’s lab is to practice writing recursive methods by competing as many CodingBat recursion exercises as possible in 50 minutes.

Creating an Account

  1. Navigate to the CodingBat web-site
  2. If you already have an account, log in. Otherwise, use the “create account” link on the upper right portion of the page to create a new account.
    • Please choose your official school email address unless you’re creating a second codingbat account due to being locked out.
  3. Once your account is created, click on the <code>prefs</code> link and:
    1. enter the email address of you instructor in the Share To box at the bottom of the page. (e.g. duanzx@jmu.edu, stewarmc@jmu.edu, wangid@jmu.edu, or weikleda@jmu.edu) and click the Share button
    2. enter your names in the Memo box and click the Update Memo button.
  4. In principle, it should be possible to grade your work through the sharing mechanism from the previous step. Just in case that doesn’t work you should save copies of your solutions to a text file.

Advice

  1. Several of the exercises below involve string manipulation. Here are some helpful String methods:
    • someString.length() returns the number of characters in a string.
    • someString.substring(0, 1) returns the the first letter of someString.
    • someString.substring(1) returns everything after the first letter. This will return the empty string ("") if the string only has one letter.
  2. Other methods involve processing integers one digit at a time. Here we can use the / and % operators:
    int num = 745;
    int last = num % 10;   // evaluates to 5, the last digit of 745.
    int rest = num / 10;   // evaluates to 74, all of the digits except the last.
    

Start Programming

You are not required to work on these in order, but they do build on each other to some extent. If the exercises from Group 1 seem too easy, feel free to skip ahead to Group 2. To receive credit for the lab you must finish at least four exercises beyond “bunnyEars”.

Don’t use the “next” button to move between exercises: after you have completed an exercise come back to this page and select the next one.

Group 1

  1. bunnyEars (Includes hints and solution)
  2. count7
  3. sumDigits
  4. array6
  5. countX
  6. changeXY
  7. endX
  8. nestParen
  9. parenBit

Group 2

  1. groupSum
  2. groupSum6

Submitting

By sharing your codingbat account with your instructor as outlined above, your instructor will be able to see your work. As long as you also followed the instructions about the Memo field in coding bat, your instructor will be able to award you credit for the lab.

For full credit, you must finish at least four exercises beyond “bunnyEars”.

Last modified May 1, 2023: student-sourced updates (1f18b77)