COMP2100/2500 Software Construction
Paced programming exercises — Homework 2010

this is the 2010 version, likely to be updated for 2011

Quick Homework Menu

  1. revision: array ordering
  2. prime factors
  3. line counter
  4. writing 1-3 digit numbers as words
  5. writing larger numbers as words
  6. sorting integers using a binary tree
  7. making change
  8. commonest words part 1
  9. extract from an archive
  10. commonest words part 2
  11. GUI
  12. shell

Explanation

Weekly homework is an important part of learning and self-development in the COMP2100/2500 Software Construction courses. The homework exercises are not given any assessment marks. However before you decide that you will save time by not doing the homework, consider this:

We guarantee that one of the homework exercises (in a slightly modified form) will be repeated on the final examination test. If you will have not done it, you find yourself at a serious disadvantage, in a time-pressure situation.

Clearly you are free to collaborate on the homework exercises as much as you like. My recommendation, however, would be to make a serious effort to do the homework by yourself. A good idea would be to set aside a particular time each week for homework. Then when you have completed it, you could get extra value from it by comparing your solution with other students and discussing the differences. There is almost no benefit from looking for other people's solutions (or my sample solutions, if available) before trying it seriously yourself: you just cannot improve your programming skills that way.

Aims

  1. To provide you with an opportunity and an incentive to do regular programming, thus improving your skills.

  2. To provide an opportunity for you to learn and practice the PSP.

  3. To help you practise the use of version control every time you code, so it can be as natural as breathing.

The initial aim some years ago was just #2 above: practise PSP. The idea was that there is little point in doing the PSP on challenging programming tasks that cover completely new ground for you. While you are learning new skills there is no point in recording your time and trying to learn something from the statistics. You have a much better chance of learning something from the PSP while carrying out routine programming tasks — ones that aren't a major challenge involving new concepts and techniques. The idea is that the homework programs should be relatively straightforward. Your challenge is to write them well, in a reasonable time, with as few defects as possible and to learn to predict your own process.

But it is also true that in 2002—2007 many students found that doing the homework tasks helped them to improve their programming skills quite dramatically. What we had expected to be easy tasks turned out to be rather difficult at first for many students, but by mid-way through the semester their skills had improved to the point where they were much more confident and capable programmers. If you are weak in Java programming at the start of the semester, look at these weekly programming exercises as an opportunity to turn that weakness into a strength.

The exercises v3: 2010

Here are the homework exercises, some estimate of size of the solution, and recommended test methods (in some cases).

link to specification brief description estimated size:
total lines/ NCNB[1] lines
classes/ methods test method

Homework 1.

gentle revision: an ordered array 66 / 501 class / 2 methods set up calls in a main method to test
  • an empty array (expect result: true)
  • a single element array (expect result: true)
  • an array that is in order (with values spanning zero) (expect result: true)
  • out of order at the start (expect result: false)
  • out of order at the end (expect result: false)
  • out of order somewhere in the middle (expect result: false)
Homework 2.Prime Factors 55/481 class, 2 methodssee test values and expected outputs in specification

Homework 3.

Counting logical lines of code. 104/ 651 class / 4 methodsTest cases: use any (small) Java source files, count by hand.
Or use the example files in directory http://cs.anu.edu.au/student/comp2100/homeworks/hw03 with counts as shown here
AttributeList.java97
XmlContainerElement.java 176
XmlDataElement.java44
XmlElement.java47

Homework 4.

Writing numbers out in words, part I (small numbers). 101 / 701 class / 2 methods
three digits: java NumbersToWords 346 three hundred and forty-six
two digits: java NumbersToWords 46forty-six
one digit: java NumbersToWords 3three
outside boundary: (low): java NumbersToWords 0error message
inside boundary: (low): java NumbersToWords 1one
outside boundary (high): java NumbersToWords 1000error message
inside boundary (high): java NumbersToWords 999nine hundred and ninety-nine
spelling of "forty": java NumbersToWords 42forty-two

Homework 5.

Writing numbers out in words, part II (big numbers). 142 / 1111 class / 3 methods lower boundary is as above. Upper boundary is determined by representation of Integer on your system.
Equivalence class tests: a set of 7 numbers with length 1, 2 (simple), 2 (composite), 3, 4, 7 and 10 digits.
length 1 digitjava Words 7seven
length 2 digits (teens)java Words 17seventeen
length 2 digits (composite)java Words 27twenty-seven
length 3 digitsjava Words 347three hundred and forty-seven
length 4 digitsjava Words 1234 one thousand, two hundred and thirty-four
length 7 digitsjava Words 1234567one million, two hundred and thirty-four thousand, five hundred and sixty-seven
length 10 digitsjava Words 1234567891one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety-one
Homework 6. Sorting integers using a binary search tree. 98 lines 4/7 classes/methodstests

Homework 7.

Making change. (How many of each type of coin do you need to make a particular amount?) lines classes/methodstests

Homework 8.

Commonest words (part 1): Finding the five commonest words in a text file. 373 / 317 for the complete solution: (I wrote my own version of Binary Tree) 11 classes / 53 methods (complete solution, with debugging Equivalence cases? boundary cases? hmmm... one for the student to really think about.
You can test the function of your program against an alternative implementation - a shell script commonestFive.sh and compare for any text input (Note: this script does not sort equally frequent words into alphabetical order, as the homework specification requires).

Homework 9.

archive files creation and extraction 184 3/10 tests

Homework 10.

Commonest words part 2. 371 lines 11/53 classes/methods tests

Homework 11.

Graphic User Interface GUI lines classes/methods tests

Homework 12.

Shell programming lines not applicable classes/methodstests

Notes and references

  1. NCNB: "non-comment, non-blank" - an indication of the actual code size of a source program file, counting the lines which are not comments and not blank. If the program has a standard layout of statements and other constructs this is a fair measure of comparable size. NCNB gives a smaller count than is measured by LineCount (homework-05) because it excludes all comments.
____________________________________________________

Copyright © 2006, 2008, 2009, 2010 Ian Barnes, Chris Johnson, The Australian National University
$Revision: 2.18 $ $Date: 2011/02/01 07:09:56 $
Feedback & Queries to comp2100@cs.anu.edu.au