Professional Documents
Culture Documents
Introduction
This assignment is presented in two stages. The first stage is worth 50% of the full
assessment mark and does not involve the use of inheritance. The second stage
makes up the rest of the marks and takes advantage of inheritance.
The work you submit must be your own. We will run checks on all submitted work in
an effort to identify possible plagiarism, and take disciplinary action against anyone
found to have committed plagiarism.
• One of the most common reasons for programming plagiarism is leaving work
until the last minute. Avoid this by making sure that you know what you have
to do (that is not necessarily the same as how to do it) as soon as an
assessment is set. Then decide what you will need to do in order to complete
the assignment. This will typically involve doing some background reading
and programming practice. If in doubt about what is required, ask a member
of the course team.
• Another common reason is working too closely with one or more other
students on the course. Do not program together with someone else, by which
I mean do not work together at a single PC, or side by side, typing in more or
less the same code. By all means discuss parts of an assignment, but do not
thereby end up submitting the same code.
• It is not acceptable to submit code that differs only in the comments and
variable names, for instance. It is very easy for us to detect when this has
been done and we will check for it.
• Never let someone else have a copy of your code, no matter how desperate
they are. Always advise someone in this position to seek help from their class
supervisor or lecturer. Otherwise they will never properly learn for themselves.
The Task
The task involves implementing a sort of simple interactive language that can
manipulate the shapes seen in the figures project from chapter 1. The assignment
files use a different version of that project – one that includes the use of inheritance
to avoid code duplication. Inheritance is covered in chapters 8 and 9 of the course
book.
You have been provided with a starting point for the assignment:
https://www.cs.kent.ac.uk/~djb/co320/LOCAL-ONLY/assign3.zip
You are provided with the source code of four shape classes – Circle, Person,
Square and Triangle – but the BlueJ editor for these classes is currently showing
the Documentation view of them rather than the Source Code view. The
Documentation view is simply the javadoc documentation for the classes that has
been generated from the comments and method headers that are in the source
code. The idea is that it should be easy to use these classes without needing to see
details of the source code. You can flip the views by using the drop-down menu in
the top-right corner of the editor window. In essence, these classes have exactly the
same methods as those in the figures project from chapter 1, but their
implementation differs slightly.
Requirements
The following sections give details of the tasks that are required. In completing
these, please bear in mind that all the code you write should be well laid out and the
fields, methods and constructors should be properly documented, using the style that
is used in this course. In particular, use of javadoc-style notation is a requirement
and adherance to these will be included in the marking scheme.
There should be no need to change the source code of any of the provided classes
with the exception of ShapeProgrammer. If you feel that you need to make changes
to other classes then ask me whether this is acceptable or appropriate before doing
so.
Background
The idea is that users should be able to interactively create, name and manipulate
shapes by typing commands into the terminal window. If you create a
ShapeProgrammer object and then call its program method, the following will
appear in the terminal window:
If you type circle at the prompt (>) in the window then a blue circle will appear on
a canvas. If you type quit then the program method will terminate. That is pretty-
much all of the functionality that is currently available in the ShapeProgrammer
class. Your task will be to add more.
What to add
Your task is to enhance the ShapeProgrammer class so that users can create and
name shapes, and then manipulate those shapes via the names they have been
given. The manipulations will simply be calls to the standard methods of the shape
classes, such as makeVisible, moveLeft, etc. In Stage One of the assignment,
you work with just Circle objects and you can safely ignore the other shapes for the
time being. In Stage Two, it should be possible to create and manipulate the other
shapes in the same way as for circles.
The shape language – Stage One (50%)
The ‘shape language’ you will implement must implement the command set defined
below. Note that, in stage one, this language only applies to Circle objects. You
can ignore all other shape types. The commands of the language are defined as
follows:
• circle name
where name may be any string of one or more characters that does not
include a whitespace character (space, tab or newline). This means, create a
Circle object and associate it with the given name. For instance:
Storing an association between the name and the created object is very
important because the name will be used in later commands to refer to that
particular Circle object. Note that ‘name’ here does not mean a variable name.
Inside the program ‘name’ will be represented as a String, such as "ball" or
"very-large-ball" retrieved from the array of strings returned by the
InputReader. Hint: Use a HashMap to create the association between the
name and the created Circle object.
• name left
Call the moveLeft method on the Circle object that was previously created
with the given name. For instance:
For this to work, there must have been a previous command to create a Circle
object with the associated name very-large-ball.
• name no-parameter-method
Call a particular method on the Circle object known as name. The string no-
parameter-method will be your chosen name for any of the following
methods of a Circle: moveLeft, moveDown, moveUp, moveRight,
makeVisible, makeInvisible. All of these methods do not take any
parameters.
Note that the string used to select a particular method does not have to
exactly match the method name. For instance, in the previous example we
used left as the word to call the moveLeft method. Here we are just
extending that idea to cover all of the methods that do not take parameters.
• forget name
This command should remove the association between name and its
associated Circle object. In effect, the name should be removed from the
HashMap. For instance:
If no Circle object has been created with that name then an error message
should be printed to tell the user that this is the case. The Circle object that is
being forgotten should be made invisible so that it no longer appears on the
drawing. Any future commands referring to sun would now produce an error
message, unless a fresh shape is created and the name reused.
Use the changeColor method of Circle to change the colour of the Circle
associated with name to be the given colour. The colour-string should be one
of: "black", "blue", "green", "magenta", "red", "white",
"yellow". If colour-string is not one of the recognised colour strings
then print an error message. NB: You may use either the US or UK spelling of
colour in this command.
You will obviously need to add an additional shape-creation command for each of
the additional three shapes:
• person name
• square name
• triangle name
In fact, this extension should not require very much work, because polymorphism
provides a simple solution.
• Add commands that will allow the following four methods to be called on a
shape: moveVertical, moveHorizontal, slowMoveVertical and
slowMoveHorizontal. Note that all of these methods require a single
integer parameter value, so the commands will be more complicated to
implement. For instance:
To make this easier, the InputReader class has the following methods:
isAnInt and convertToInt. Both take a String parameter. The first returns
true if the String passed to it contains numerical characters like an integer,
and false otherwise. The second coverts the numerical characters of its
String parameter to an integer value and returns that value. These methods
will make it very easy to check that the third word of a command is, indeed, a
number and then get the numerical value.
Although all the shape classes have a changeSize method, the parameters they
take are not consistent. Some take one parameter (Circle and Square) while the
others take two (Person and Triangle).
• Add a resize command that can be called on any shape, but have the
program check that the correct number of values have been passed for the
shape to which it is being applied. For instance, if sun is a Circle and robot
is a Person, the following uses of resize would be correct:
Have the program print an error message if the correct number of values has
not be provided. It is not acceptable to always specify two values and only use
the first in the case of Circle and Square!
Getting help
If you need help with the assignment, there are various places you can go. You will
not lose marks if you ask for help.
• You can ask questions on the anonymous question-asking page.
Be very careful about asking for help from other students on the course, or students
who have taken the course before, other than as described above. If in doubt about
what is appropriate, check the plagiarism guidelines above and/or ask the module’s
lecturer.
Finally
Before you submit your assessment, thoroughly test the whole class to make sure
that nothing you added later has broken anything added earlier. If you are unable to
complete the class – even if you cannot get it to compile – still submit what you have
done because it is likely that you will get at least some credit for it.