CECS Home | ANU Home | Search ANU
The Australian National University
ANU College of Engineering and Computer Science
School of Computer Science
Printer Friendly Version of this Document

UniSAFE

Software Construction

Homework 1 - COMP2100/2500 - DCS - ANU

The Australian National University College of Engineering and Computer Science

COMP2100/2500 Software Construction
Homework 1
$Revision: 2.1 $ $Date: 2009/02/17 04:56:25 $

Note: For Exercises 1–3, see Lecture 2: PSP for details.)

Exercise 1

Get hold of a lab notebook (either a proper book or a ring binder) and get it set up ready to use for PSP in COMP2100.

Exercise 2

Start recording all time you spend on COMP2100 work on a Time Recording Log form.

Exercise 3

Before your lab, complete a Weekly Activity Summary, breaking your time use down by day and by the categories given in Lecture 2.

Exercise 4

Write the following program, making a note of how long it takes you to complete it. (You do not have to follow the PSP while you write this program, but recording your time is the first step towards doing it. Wait until you have learned the initial process in Lecture 2 and Lab 1.)

Write and test a method called isOrdered that determines whether an array of ints is in non-decreasing order.

The signature of the method is

    /**
     * @param X an int array of any length (including empty)
     * @return true if the elements in X are in order of non-decreasing (rising) values
     **/
    boolean isOrdered(int[] X)
You should write several calls to test your method: it is good practice (you'll learn why later) to include a test of the boundary cases. These are
  • an empty array
  • a single element array
  • an array that is in order (with values spanning zero)
  • out of order at the start
  • out of order at the end
  • out of order somewhere in the middle.

Deliverables

It's always imnportant to remember what the client actually requires. It may not be what you think is the solution to the prblem that you saw in when you read the specification—read it again.

When you have completed this program, print out a copy of the source code and the output, and store them in your lab notebook (either by sticking them in or by punching holes and putting them in your ring binder).

Exercise 5 - extension

If you thought that was so easy...

  1. rewrite (a new version) using arrayList<Integer> instead of the array of int.
    This requires you to find out how to create an arrayList from an array (try to avoid a loop for doing this - find the direct conversion ).
  2. extend this into to the abstract space: rewrite for the generic case of any element type that extends (or implements) the Comparable interface, that is, for an arrayList<B extends Comparable<?>>


Copyright © 2009, Chris Johnson, The Australian National University

Feedback & Queries

comp2100@cs.anu.edu.au
$Revision: 2.1 $ $Date: 2009/02/17 04:56:25 $ $Author: cwj $