The University of Hong KongDepartment of Computer ScienceCOMP2396 Object-oriented Programming and JavaAssignment 1Deadline: 11:55pm, 14th Feb, 2019.OverviewThis assignment tests your understanding of classes and objects, and their implementations inJava. You are required to implement 4 classes, namely Shape, Square, Triangle and Circle.The Square class, Triangle class and Circle class are used to model squares, triangles, andcircles, respectively. They are subclasses of the Shape class which provides an abstraction ofgeneral shapes. For each of the 4 classes mentioned above, you are required to design andimplement a tester class to test the correctness of your implementation. You are also requiredto write Javadoc for all public classes and their public class members.SpecificationsThe Shape classThe Shape class is used to model general shapes. It has instance variables for storing color,fill-type, orientation, screen coordinates of the center, and local coordinates of the vertices ofa shape. It has methods for getting the screen coordinates of the vertices of a shape. Below isa detailed description for the Shape class.Specification of the Shape class:instance variablesColor color – a Color object specifying the color of the shape. To use the Color class,place “import java.awt.Color;” at the top of the source file of your Shape class.Please refer to http://docs.oracle.com/javase/8/docs/api/java/awt/Color.html for detailsof the Color class.boolean filled – a boolean value specifying whether the shape is filled or not filled.double theta – a double value specifying the orientation (in radians) of the shape in thescreen coordinate system (see Figure 1).double xc – a double value specifying the x-coordinate of the center of the shape in thescreen coordinate system.double yc – a double value specifying the y-coordinate of the center of the shape in thescreen coordinate system.double[] xLocal – an array of double values specifying the x-coordinates of thevertices (in counter clock-wise order) of the shape in its local coordinate system.double[] yLocal – an array of double values specifying the y-coordinates of thevertices (in counter clock-wise order) of the shape in its local coordinate system.methods:void setVertices(double d) – a method for setting the local coordinates of thevertices of a shape. This is a dummy method and is supposed to be overridden in thesubclasses.void translate(double dx, double dy) – a method for translating the center of theshape by dx and dy, respectively, along the x and y directions of the screen coordinatesystem (i.e., dx and dy should be added to xc and yc respectively).void rotate(double dt) – a method for rotating the shape about its center by an angleof dt (in radians) (i.e., dt should be added to theta).int[] getX() – a method for retrieving the x-coordinates of the vertices (in counterclock-wise order) of the shape in the screen coordinate system (rounded to nearestintegers).int[] getY() – a method for retrieving the y-coordinates of the vertices (in counterclock-wise order) of the shape in the screen coordinate system (rounded to nearestintegers).* You should make all the instance variables and methods public by using the public accessmodifiers.Figure 1. Relationship between local and screen coordinates of the vertices of a shape.The screen coordinates of the vertices can be computed from the local coordinates of thevertices based on the orientation and center of the shape using the following formula:where (x, y) and (x’, y’) denote the local and screen coordinates of a vertex, respectively, ?the orientation (in radians) of the shape, and (xc, yc) the screen coordinates of the center ofthe shape.* You may use Math.sin() and Math.cos() to compute sine and cosine functions, andMath.round() to round a number to its nearest integer. Please refer tohttps://docs.oracle.com/javase/8/docs/api/java/lang/Math.html for details of the Math class.local coordinate system screen coordinate systemThe Square classThe Square class is used to model squares. It is a subclass of the Shape class and it inherits allthe instance variables and methods of the Shape class. The Square class overrides thesetVertices() method for setting the local coordinates of the 4 vertices of a standard square.Below is a detailed description for the Square class.Specification of the Square class:instance variables inherited from Shape:color, filled, theta, xc, yc, xLocal, yLocalmethods inherited from Shape:translate, rotate, getX, getYoverriding method:void setVertices(double d) – a method for setting the local coordinates of the 4vertices of a standard square. Here, a standard square has its center located at (0, 0) andits sides being parallel to the x- and y-axes of its local coordinate system. The parameterd specifies half-the-length of a side of the square.* You should make all the instance variables and methods public by using the public accessmodifiers.Figure 2. The local coordinates of the 4 vertices of a standard square with a side of 2d.For a standard square with a side of 2d, the local coordinates of its 4 vertices in counterclockwise order starting from the lower right corner are (d, d), (d, -d), (-d, -d) and (-d, d),respectively.The Triangle classThe Triangle class is used to model triangles. Like the Square cl代做COMP2396作业、代写Computer Science作业、代写Java课程设计作业、Java编程语言作业代做 ass, it is a subclass of theShape class and it inherits all the instance variables and methods of the Shape class. TheTriangle class overrides the setVertices() method for setting the local coordinates of the 3vertices of a standard triangle. Below is a detailed description for the Triangle class.Specification of the Triangle class:instance variables inherited from Shape:color, filled, theta, xc, yc, xLocal, yLocalmethods inherited from Shape:translate, rotate, getX, getYoverriding method:(d, d)(-d, -d) (d, -d)(-d, d)void setVertices(double d) – a method for setting the local coordinates of the 3vertices of a standard triangle. Here, a standard triangle is an equilateral triangle havingits center located at (0, 0) and one of its vertex on the positive x-axis of its localcoordinate system. The parameter d specifies the distance from the center of thetriangle to any of its vertices.* You should make all the instance variables and methods public by using the public accessmodifiers.Figure 3. The local coordinates of the 3 vertices of a standard triangle with a distance of d from its center to any of itsvertices.For a standard triangle with a distance of d from its center to any of its vertices, the localcoordinates of its 3 vertices in counter clockwise order starting from the one on the positivex-axis are (d, 0), (?? cos ?/3 , ?? sin ?/3) and (?? cos ?/3 , ? sin ?/3), respectively.The Circle classThe Circle class is used to model circles. Like the Square class and the Triangle class, it is asubclass of the Shape class and it inherits all the instance variables and methods of the Shapeclass. The Circle class overrides the setVertices() method for setting the local coordinatesof the upper left and lower right vertices of an axis-aligned bounding box of a standard circle,as well as the getX() and getY() methods for retrieving the screen coordinates of the upperleft and lower right vertices of this bounding box. Below is a detailed description for theCircle class.Specification of the Circle class:instance variables inherited from Shape:color, filled, theta, xc, yc, xLocal, yLocalmethods inherited from Shape:translate, rotateoverriding methods:void setVertices(double d) – a method for setting the local coordinates of the upperleft and lower right vertices of an axis-aligned bounding box of a standard circle. Here,a standard circle is a circle having its center located at (0, 0) of its local coordinatesystem. The parameter d specifies the radius of the circle.int[] getX() – a method for retrieving the x-coordinates of the upper left and lowerright vertices of an axis-aligned bounding box of the circle in the screen coordinatesystem (rounded to nearest integers).int[] getY() – a method for retrieving the y-coordinates of the upper left and lowerright vertices of an axis-aligned bounding box of the circle in the screen coordinatesystem (rounded to nearest integers).* You should make all the instance variables and methods public by using the public accessmodifiers.Figure 4. The local coordinates of the upper left and lower right vertices of an axis-aligned bounding box of astandard circle with a radius of d.For a standard circle with a radius of d, the local coordinates of the upper left and lower rightvertices of its axis-aligned bounding box are (-d, -d) and (d, d), respectively. Theircorresponding screen coordinates are (-d + xc, -d + yc) and (d + xc, d + yc), respectively,where (xc, yc) denote the screen coordinates of the center of the circle.The tester classesThe tester classes are used to verify the correctness of your implementation of the above 4classes. You should design your own tester classes. Generally, your tester classes shouldcreate an object of a class and access all its instance variables and methods using the dotoperator, and print out debugging messages to the console. (You do not need to actually drawthe shapes in your tester classes!)A simple GUI for visualizationFigure 5. Assign1_GUI.java implements a simple GUI for visualizing the shape classes.(d, d)(-d, -d)Assign1_GUI.java implements a simple GUI for you to test and visualize your shape classes.The GUI draws a square, a circle and a triangle on the canvas. When the user clicks on ashape, the shape rotates clockwise 360o.Marking SchemeMarks are distributed as follows:- Implementation of the Shape class and its tester class (40%)- Implementation of the Square class and its tester class (10%)- Implementation of the Triangle class and its tester class (10%)- Implementation of the Circle class and its tester class (20%)- Javadoc and comments (20%)SubmissionPlease pack the source code (*.java) of your shape classes and tester classes into a single zipfile, and submit it to the course Moodle page.A few points to note:- Always remember to write Javadoc for all public classes and their public classmembers.- Always remember to submit the source code files (*.java) but NOT the bytecodefiles (*.class).- Always double check after your submission to ensure that you have submitted themost up-to-date source code files.- Your assignment will not be marked if you have only submitted the bytecode files(*.class). You will get zero mark for the assignment.- Please submit your assignment on time. Late submission will not be accepted.~ End ~转自:http://ass.3daixie.com/2019021667777723.html