(Week 5 Starting Monday October 23rd 2006)

Hand in date - one week after your scheduled tutorial session in week 5.

Aims and Objectives: Provide an opportunity for students to design, implement and test a simple Java program that performs some straight forward arithmetic and makes use of one or more constants.



Figure 1 shows an open topped iron barge of length L, Breadth B and Height H. Knowing that the iron from which the barge is built weighs about 1.06 tonnes per m2, we can calculate the draft d of the barge (the proportion of H which is submerged) using Archimedes' Principle:

When a body is immersed in a liquid it displaces a volume of liquid equivalent to the mass of the body.

(1 m3 of fresh water weighs 1 tonne). The calculation comprises three steps:

  1. Calculate the surface area of the barge using the identity:
    surfaceArea (m) = 2H(L+B)+LB
  2. Calculate the mass (weight) of the barge using the identity:
    massOfBarge (tonnes) = surfaceArea X 1.06
  3. Calculate the draft using the identity (assuming water weighs 1 tonne per m3):
    draft (m) = massOfBarge/(LXB)



surfaceArea = (2x5)(16+6)+(16*6) = 10(22)+96 = 220+96 = 316

massOfBarge = 316*1.06 = 334.96

draft = 334.96/(16*6) = 3.49m

Of course if the required draft exceeds the height of the barge the barge will sink but ignore this minor inconvenience.

You should develop and implement a Java program which, given a barge defined in terms of inputs for L, B and H, outputs the associated draft.


Figure 1: Geometry of an open topped floating barge

TESTING Given that the problem has 3 inputs which can be either, 0 or a positive or negative number; arithmetic testing dictates that we require 33 (27) separate tests! Do not waste your time processing 27 separate test cases, instead write an additional application program --- a test harness --- to test your program (there is no need to hand in any design documentation for the test harness).


  1. Refer to the Pythagoras and 2D geographic distance example problems presented in lectures to get a "feel" for the nature of the problem solution.
  2. Example test harness code can be found in the notes with respect to the Pythagoras, and 2-D geographic distance example problems.

Remember that guidance notes on (1) the execution of COMP101 practicals, and (2) the presentation of work are available.

N.B. Should you, in any of the practicals, wish to make use of classes that have been presented in lectures or that are contained in the notes to date there is no need to provide design, implementation or testing details of those classes --- although you should note in your write up the fact that you are using additional classes that are not part of the Java API and not of your own design.


Your solution should comprise the following:

  1. Requirements: Summary of the above requirements statement.
  2. Analysis and Design: A short (one paragraph) description of your analysis of the problem including a Class Diagram outlining the class structure for your proposed solution, a complete set of "summary tables", and Nassi-Shneiderman chart for each. Note that your solution should comprise two classes: an "application class" and a "target class".
  3. Implementation: Your Java source files, i.e. the relevant .java files, not the class (.class) files.
  4. Testing: A set of proposed test cases presented in tabular format, and evidence of the results of testing (the simplest way of doing this is to cut and paste the result of running your test cases into your report).
  5. Declaration: A completed "Declaration on Plagiarism and Collusion".

As with the previous exercise all supporting documentation (i.e. excluding source files) should be prepared as a single Microsoft Word file. Word includes a simple drawing capability which suffices when creating Class Diagrams and Nassi-Shneiderman charts. Remember, the easiest way of including "evidence of testing" is to simply cut and paste it into your word document.

Once completed you should "up load": (i) your Java source files (extension .java), (ii) your report (word document) and (iii) a comleted "Declaration on Plagiarism and Collusion", to the CS department's electronic practical assignment submission system.


90% of the marks will be distributed evenly between: Analysis and Design; Implementation; and Testing. The remaining 10% will be awarded for "overall presentation" (marks will be deducted if there is no "Declaration on Plagiarism and Collusion").

Guidance notes for the execution of COMP101 practicals are available. See also notes on practicals and course work for general guidance on the presentation of work, the COMP101 marking scheme and late submission policy.

Created and maintained by Frans Coenen. Last updated 30 October 2006