Java代写 | COMPSCI 230B Assignment
本次Java代写是开发Bounce应用程序,并进行相应的测试
COMPSCI 230B Assignment
Assessment criteria
(2 marks) submit your source code (including the original Canvas code) to the Assignment
Drop Box (ADB – adb.auckland.ac.nz) by Week 10 (Friday 10:00pm, 29 May 2020).
o
The code submission must take the form of one zip file that maintains the Bounce
package structure.
o
o
You must name your zip file as “YourUPI_230a3_2020.zip”.
You may make more than one ADB submission, but note that every submission that
you make replaces your previous submission.
o
o
Submit ALL your files in every submission.
Only your most recent submission will be marked.
o
o
Please double check that you have included all the files required to run your program
in the zip file before you submit it. Your program must compile and run (through Java
1
.8) to gain any marks.
Include the code for creating and showing all required shapes in
AnimationViewer class.
NOTE: It would be ideal to first complete all tasks (that you are able to complete) in an IDE like
Eclipse, and then only proceed to answer CR3 questions once you have finished writing working
code for this iteration in your IDE.
Constraints
For all three parts of the of the assignment, any changes you make to the Shapeclass hierarchy must
not break existing code (e.g. the AnimationViewerclass). In particular, class Shape must provide
the following public interface (note this is not the Java “interface”; here the term “interface” refers to
the set of public methods in a class that may act as entry points for the objects of other classes) at all
times:
void paint(Painter painter)
void move(int width, int height)
Task 1: add class NestingShape
Define a new subclass of Shape, NestingShape. A NestingShape instance is unique in that it
contains zero or more shapes that bounce around inside it. The children of a NestingShapeinstance
can be either simple shapes, like RectangleShapeand OvalShapeobjects, or other NestingShape
instances. Hence, a NestingShape object can have an arbitrary containment depth.
The Javadoc description for NestingShapeis given in Appendix 1. Appendix 2 describes additional
functionality required of class Shapefor this task.
The resulting Shapeand NestingShapestructure is an application of the Composite design pattern.
Specific requirements
Specific requirements are listed in the Appendices 1 and 2.
Once created, edit the AnimationViewerclass to add in instance of NestingShape, with a depth
of at least three containment levels, to your animation.
Hints
A NestingShapehas its own coordinate system, so that Shapeinstances within it are within
the coordinates of the NestingShape. So, if a Shape with a location of (10,10) is in a
NestingShape, it will be located 10 pixels below and 10 pixels to the right of the top-left
corner of the NestingShape.
In addition to implementing new methods in class NestingShape, methods handling
painting and movement inherited from Shape will need to be overridden to process a
NestingShapeobject’s children.
The method that Shape’s subclasses implement to handle painting should not be modified
when completing this task. In other words, Shape objects should not have to be concerned
with whether or not they are children within a NestingShapewhen painting themselves.
One way of cleanly implementing NestingShape’s painting behaviour is to use graphics
translation – adjusting the coordinate system by specifying a new origin (the
NestingShape’s top left corner) that corresponds to a point in the original coordinate
system. This can be achieved using Painter’s translate()method. Once translated, all
drawing operations are performed relative to the new origin. Note that any translation should
be reversed after painting a NestingShape.
E.g. the following code sets the new origin (0, 0) to (60, 40). After this, a Paintercall like
painter.drawRect(10, 10, 40, 20) would cause the rectangle to be painted at
absolute position 70, 50. The second translate()call restores the origin to (0, 0).
painter.translate(60, 40);
// Code to paint children …
painter.translate(-60, -40);
Testing
From the CodeRunner quiz named Bounce II, complete the first two questions:
(3 marks) Bounce II NestingShape, which runs a series of tests on your NestingShapeclass.
(1 mark) Bounce II NestingShape (static analysis), which examines the source code for your
NestingShapeclass.
Your code will need to pass all tests.
Task 2: add provision for any Shape to display text
Further develop the Shapeclass hierarchy to allow text to be displayed when a shape is painted. Text
should be centered, horizontally and vertically, in a shape’s bounding box, but may extend beyond the
left and right sides. Graphicsclass’ drawString()method and FontMetricsclass may be
used to implement the core functionality for this task.
In designing the revised class structure, you must guarantee that if a shape is associated with text that
it will always be painted. This responsibility should not be left to developers of Shapesubclasses. To
elaborate, consider the intention to make your Shapeclass hierarchy available – only the bytecode
and not the source files – to other developers. The above guarantee should hold for any Shape
subclasses added by other developers in the future. Note that since such developers will not have the
source code for your class hierarchy they cannot edit your classes; all they can do is extend the classes
that you provide.
Specific requirements
You must solve this problem by applying the Template Method design pattern. Recall the
constraint that it must be possible to call paint(Painter)and move(int, int)on any
object that is an instance of class Shapeor its subclasses.
The mandatory hook method required for the Template Method solution must be named
doPaint()and take a Painterparameter.
Class Shape and all of its subclasses should provide a 7-argument constructor where the
arguments are x, y, deltaX, deltaY, width, height and text, where text is a String. This adds the
capability for text to be supplied when constructing a shape. If other constructors are used,
the resulting shape is assumed not to have text.
During painting of a shape, any text should be painted last – so that it is superimposed over
any solid figure or image that has been painted for the shape.
Once you have implemented the text painting facility, add some shapes with text to your animation.
Testing
From the CodeRunner quiz named Bounce II, complete the remaining two questions:
(3 marks) Bounce II Shapes with text, which runs a series of tests on your classes.
(1 mark) Bounce II Shapes with text (static analysis), which examines the source code for your
classes.
CONTACT
Service Scope
C|C++|Java|Python|Matlab|Android|Jsp|Prolog|MIPS|Haskell|R|Linux|C#|PHP|SQL|
.Net|Hadoop|Processing|JS|Ruby|Scala|Rust|Data Mining|数据库|Oracle|Mysql|
Sqlite|IOS|Data Mining|网络编程|多线程编程|Linux编程|操作系统|
计算机网络|留学生|编程|程序|代写|加急|个人代写|作业代写|Assignment