CSC 171
Homework 7, aka Take-Home Final Exam
Loops and Assignment

Assigned May 1, due May 15

This assignment will not be accepted late! Besides, many of these problems will help you with the in-class final exam, so try to get some of them done before then.

Reading and Reactions (to be done individually)

Re-read the articles and quotations from homework 1, and read this brief article on computational thinking for non-computer scientists. Choose several related adages, or one longer article, that mean more to you than they did at the beginning of the semester.

Write an essay of three to six well-structured paragraphs on what the readings really mean in practice. Do you agree or disagree? Support your claims with specific examples from your experience this semester.

Programming problems

For each method, be sure to follow the design recipe for methods.

For each animation, be sure to follow the design recipe for animations.

Be sure to choose meaningful names for methods and parameters, and watch for opportunities to re-use methods you, I, or Dr. Stemkoski have already written.

Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description). Since the on-line PSP forms aren't completely fixed yet, you may want to do this by keeping track in a text file and turning it in.

    Lists

  1. Choose two of the IntList methods from homework 5, and re-implement them as static methods that use loops instead of recursion.

    (We've already given a solution to addAll in lecture, so don't pick that one.)

    If you're thinking of convertReversed, I suggest doing a version with unreversed digits instead: for example, if the digits were 6, 2, 0, 5, 3, the right answer should be 62053. (The "reversed" version was easier for structural recursion; the "unreversed" version is easier for a loop.)

    You may use while-loops or for-loops.

  2. Choose one one of your animations from homework 5, and re-implement it with methods that operate on List<Whatever> "from the outside" using loops rather than recursion.

    You may use while-loops or for-loops.

  3. Strings

  4. Choose one of the String methods from homework 6, and re-implement it using loops instead of recursion. You may use while-loops or for-loops.

  5. Whole numbers

  6. Write a static method pyramid that takes in a whole number and produces a picture of a triangular stack of balls with that many on a side. For example, pyramid(5).show(); should produce the result at right. Use loops, not recursion.

    Hint: you can do this either with nested loops, or with two separate methods that each have a single loop. You may use while-loops or for-loops.


  7. Write a static method printMultTable that takes in two positive integers maxColumn and maxRow and prints (to System.out) a multiplication table with columns running from 1 to maxColumn and rows running from 1 to maxRow. Use loops, not recursion. Here's an example output:

    I used the "tab" character ("\t") to get things lined up nicely in columns; there are more sophisticated ways to do it, but that will do for this assignment. Remember that System.out.println prints something and then goes on to the next line, while System.out.print prints something and stays on the same line.

    Hint: you can do this either with nested loops, or with two separate methods that each have a single loop. The loops may be either for-loops or while-loops.

  8. Input streams and scanners

  9. Re-implement the countLongLines method from homework 6 using loops instead of recursion, both for countLongLines and any helper methods you may need. (You may find it easier to write a slightly different helper method from the one you used in homework 6.)

    You may use nested loops, or two methods with one loop each. You may use while-loops, "for-each" loops, or regular for-loops.

  10. ArrayLists

  11. Choose one of the IntList methods from homework 5, and re-implement it as a static method that takes in the standard ArrayList<Integer> type rather than the IntList or List<Integer> types we invented in class. You may use while-loops, "for-each" loops, or regular for-loops.

  12. Re-implement the tallyVotes method to produce an ArrayList<Candidate> rather than a List<Candidate>. (The method may take in either the standard ArrayList<String> or our List<String>, whichever you prefer.) Use loops rather than recursion.

    You should create a new ArrayList only once when tallyVotes is called; the rest of the method (and any helper methods) should modify an existing ArrayList rather than building a new one. Likewise, once a Candidate has been added to the list, it should never be removed; if that candidate gets more votes later, the Candidate object should be modified rather than replaced with a new one. (This may require adding a "setter" method to the Candidate class.)

Grading standards

Error log:       /50
(I'm not grading on how many or how few errors you encountered, only on whether you recorded them adequately.)

Programming: To save time and get you feedback more quickly, we won't grade all of the problems, but a selection of them. Each animation requires writing a class with two or more methods; in some cases you'll also need to write a new class to be the model.

General skills:

Following directions /10
Writing contracts from word problems /10
Choosing test cases /10
Choosing names; readability /10
Coding /10
Code re-use and function composition /10

Last modified:
Stephen Bloch / sbloch@adelphi.edu