com6471 Assignment 1

com6471 Assignment

Assignment 1 30 points

Purpose

  • Implement two simple programming tasks using Java;
  • Create graphical displays.
  • Create human-machine interface.

    Jug Demo

    Consider the following puzzle — ‘given a 5-litre jug, a 3-litre jug, and an unlimited supply of water, how do you measure out exactly 4 litres?’

    Task 1: Write a program code PuzzleSolution.java that graphically demonstrate a solution to the above puz- zle.

    Task 2: Write a program code InteractiveJug.java that create a user interactive program that allows the user to solve the puzzle.

    As long as your program code follows the above description and a number of restrictions in the rest of this briefing

sheet, you are allowed to use your imagination to achieve the tasks.

• •

You may have noticed that this task is an extension of Exercise 5.
You do not have to use the Jug class you have seen in Exercise 5. However I expect that, by extending both the Jug class and its demo class, you should be able to implement a clean code for the task.
The assignment brief sheet does not tell the detail. It is rather intentional because I do not want to see everybody tries to implement code that looks very similar. Instead I would like to provide broader scope for individual interpretation of the task. That is, I value your own idea / imagination.

Jug class: pourInto method
Use the add method. The scenario here is as follows: water in Jug A is transferred to Jug B; the amount of water in Jug A (ie, ‘contents’) changes before and after this operation (i.e., ‘pourInto’). ‘to jug’ in the parameter indicates the Jug B object.

Jug class: add method
Once again, the scenario here is as follows: water in Jug A is transferred to Jug B; you first need to calculate the space available in Jug B to accept water from Jug A. Question: how do you calculate the space? Initially Jug A has ‘v’ litres (specified by the parameter input to the add method). When water is poured into Jug B, there are two cases: (1) space ≥ v, and (2) space < v. For each case, find the amount of water in Jug B (ie, ‘contents’) and the amount of water left in Jug A; the latter value should be ‘returned’ by the add method.

notes

hints

Some useful methods

Although the following methods do not offer you any extra credits, you are allowed to use them if they are useful for your design. If not, you don’t need to use them and you will not be disadvantaged.

• Thread class in the java.lang package has the following method:
– public static void sleep(long millis) — where ‘millis’ presents the length of time to sleep in milliseconds that

you are able to hold execution of your program.
• With the EasyGraphics class you are able to use the following instance methods:

  • –  public void clear() — which clears all drawings from the graphics window;
  • –  public void setTitle(String title) — which sets ‘title’ on the top of the graphics window;
  • –  public void setLocation(int i, int j) — which sets the position of the graphics window at i pixels to the right

    and j pixel down from the top left corner of the graphics window.

Foundations of Object Oriented Programming 1

com6471

Assignment

Important note
You are not allowed to use any classes except:

  • classes of your own;
  • classes from the java.lang package;
  • classes from the java.io package;
  • EasyReader and EasyWriter and EasyGraphics from the sheffield package.

    but see the notes below.

    • If you ‘have to’ use some class that is not listed above, send an email to me <y.gotoh AT sheffield.ac.uk> stating (1) what class you would like to use and (2) why you would like to use. Case-by-case decision will be made.
      Be aware that use of any class that is not listed above without permission may result in massive deduction of the mark. If you did use them with permission, state the following clearly in the report — what was used, for what purpose it was used, how it was implemented, etc.
    • In particular I do not want most of classes from the java.util package to be used.
    • If you would like to use the Swing and/or AWT, send an email to me please. Permission for use will be given only if you are already familiar with the Swing/AWT and you would like to do something interesting with

      them. Otherwise I do not think the Swing package is worth the effort for this assignment.
      Be aware that use of Swing/AWT without permission may result in massive deduction of the mark. If you did use them with permission, state the following clearly in the report — what was used, for what purpose it was used, how it was implemented, etc.
      Note that I do not consider it positively or negatively if you use the Swing and/or AWT for, say, creating GUI. They may allow you to produce sophisticated graphical output easily. However they are beyond the scope of this module. Additionally I equally value efforts made, and your ideas, to create interesting graphs by using crude methods provided by EasyGraphics. (On the other hand my expectation will be much higher if the Swing package is used for the task.)

      Report

      The report should argue any issues relating to design and implementation. In particular it should outline your work in the following issues:

      • Each task description in this briefing sheet provides a rough idea only. State what your jug demo achieves in further detail.

      • Present created graphical demos.
      • Provide a short manual for user interaction.

      The report is a typed (i.e., not handwritten) description of your work. Describe your work fully in the report — the report is a part of assessment.

  • Page 1 should be the title page, consisting of (1) the title, (2) your identity (e.g., your name, registration number), (3) the following statement:

    ‘I declare that this work is my own and I acknowledge the contribution of others where appropri-

    ate’
    and nothing else.

  • The main body of the discussion starts from page 2. The reporting format is free and there is no word limit.
  • Do not include the listing of the program code.
  • You may include illustrations, figures, graphs, tables and screenshots if they help the discussion.

notes

notes

Foundations of Object Oriented Programming 2

com6471

Assignment

Download from MOLE:

‘assignment1.zip’ contains the following file: • assignment1.pdf — this briefing sheet;

Upload to MOLE:

Program source code and the report:

• sourcecode1.zip
it should include all source code that you programmed, and nothing else (i.e., do not zip bytecode, sheffield package, data files, etc.);

• report1.pdf
pdf format please.

Paper handin:

not required.

late upload rule:

  • For each day late, 5% will be deducted from your total grade.
  • Saturday and Sunday are also counted as a day.
  • The assignment will not be graded if it is upload more than a week late.

    Assessment criteria:
    15 points are allocated for each of two tasks:

    11 points ∼

    – –

code is fully functional for all requirements;
code uses appropriate Java constructs, and displays good programming style in all places (e.g., sensible use of loops, indentation, commenting);
the report presents clear, consistent and in-depth description;
flair (i.e., stylishness and originality — most important for points beyond 11);



8



∼ 7 points

  • –  code produces compile error(s); code may be partly functional;
  • –  some Java constructs are less appropriate; there are some problems with the programming style;
  • –  some important issues are missing from the report; it is less clear or inconsistent.

∼ 10 points
code compiles without an error; code is mostly, or fully functional, producing the correct outputs; code uses appropriate Java constructs, and displays good programming style in most places;
the report is mostly clear, consistent and sufficiently detailed;

Plagiarism:

  • Any work that you handin for the assignments must be your own. Plagiarism will result in a mark of 0. Allowing someone else to knowingly copy your work will also result in a mark of 0, as it would be facilitating and encouraging plagiarism.
  • Codes in the electronic handin directory may be scanned by plagiarism detection software.

Foundations of Object Oriented Programming 3