We’ve had some good progress since the end of week 1. This weekend, the coding assignment includes problems that are more involved than most of the CodingBat problems, but they don’t individually require as much reading as the alternative radices problem we worked on this week.

I encourage you all to attempt all of these problems. Please don’t forget to run the unit tests—not just when you complete the code for a problem, but along the way (e.g. when you complete the code for a key point in the assignment specifications).

These are all Maven-based projects. As with the alternative radices problem, working on a given problem will entail reading a web page with the specifications of the code to be completed (these links follow), clicking on a link in that page to accept the problem, then cloning and importing (into Eclipse) the code repository that was created for you.

Assignments

Is it a Perfect Cube?

Perfect cubes are integers which are the result of some integer raised to the $3^\text{rd}$ power. For example, $1 = 1^3$, $8 = 2^3$, $27 = 3^3$, $64 = 4^3$, etc. Thus, $1, 8, 27, 64, \ldots$ are perfect cubes.

Your task is to complete the implementation of a method that takes a long input parameter, and returns the boolean value true if the value of the parameter is a perfect cube, and false otherwise.

Oscillating Squares

To complete this assignment, you’ll implement and test a method that constructs and returns an array (of a parameter-specified size) containing values that follow a very specific sequence: $(0, -1, 4, -9, 16, \ldots)$. As you can see, the magnitude of each value is the next perfect square in the sequence ($0 = 0^2, 1 = 1^2, 4 = 2^2, 9 = 3^2, 16 = 4^2$, etc.), but the signs alternate between positive and negative.

Complementary DNA

DNA sequences are generally represented by a string consisting of the characters 'A', 'T', 'G', and 'C', representing the nucleobases adenine, thymine, guanine, and cytosine. Complementarity describes a relationship between two sequences (or one portion of a sequence with another portion of the same sequence), based on an interaction relationship between the nucleobases in each. In very general terms, A and T are complements of each other, as G and C are complements of each other.

The task here is to implement a method that processes a string, replacing each of the 4 nucleobase characters with its complement.

String Warp

In this assignment, you’ll implement and test a method that extracts a substring of a specified string, and (optionally) reverses it. Fortunately, all of this can be done using some of the core classes of the standard library—but you’ll have to figure out which classes and methods will work best for this task.

Check Digit

Many numerical and data transmission tasks involve the use of a check sum, as a simple guard against inadvertent data corruption or transposition. Some of these check sums are used to verify the digits of a number (or digit string) by computing a single check digit. One of the most widely used check-digit algorithms is the Luhn algorithm, used for computing the check digits on most types of credit cards, as well as SIM card serial numbers. Your task is to implement this algorithm to validate a String of digit characters.