1. Create an applet that draws a random number (as specified below) of rectangles and triangles and prints
a total count for each type of shape, together with some measurements for each type of shape. The applet
should:
􀀹 Draw a window of 400 by 400 pixels with a WHITE background colour.
􀀹 Determine how many rectangles and triangles should be drawn. This should be a random integer
number between 1 and 3 for each type of shape.
􀀹 All rectangles should be BLUE and all triangles should be RED.
􀀹 The size and measurements of both types of shapes to be drawn should be as follows:
o Rectangles:
􀂃 The width and height should both be random integer numbers between 20 and
30.
􀂃 If the determined width and height numbers are the same, then this is not a valid
rectangle. Create the IllegalRectangleException class to signal when
an illegal rectangle has been created. Any illegal rectangles should not be drawn
or counted.
􀂃 For each valid rectangle, determine and print their area and perimeter below the
drawn shape – assume that the rectangle’s height and width are given in
centimetres.
o Triangles:
􀂃 The base and height should both be random integer numbers between 20 and 30.
􀂃 If the determined base and height numbers are not the same, then this is not a
valid triangle. Create the IllegalTriangleException class to signal
when an illegal triangle has been created. Any illegal triangles should not be
drawn or counted.
􀂃 For each valid triangle, determine and print their area and perimeter below the
drawn shape – assume that the triangle’s base and height are given in
centimetres.
􀀹 The initial coordinates for the first shape to be drawn are (x, y) = (15, 15). You should make sure
that your shapes do not overlap and appear in sequence (as a column of shapes). Below each
shape drawn, a string should appear indicating their measurements (and the units).
􀀹 After all the rectangles and triangles have been drawn, print a string indicating the total number
of drawn shapes.
􀀹 If no shapes have been drawn, print a string saying “No valid shapes were
generated. Please try again!”.
􀀹 You should provide:
o A class that defines a general Shape (since we may want to extend this program in the
future and add other different shapes). Name your program Shape.java.
o Classes that define a Rectangle and a Triangle – they should be subclasses of
Shape and include the implementation of two methods, named calcShapeArea and
calcShapePerimeter. Name your programs Rectangle.java and
Triangle.java.
o Two classes, each containing an exception for signalling that an attempt was made to
either create an illegal rectangle or an illegal triangle. Name your programs
IllegalRectangleException.java and
IllegalTriangleException.java.
o A class with the applet. Name your program DisplayShapes.java.
o The HTML file that loads the applet. Name your file DisplayShapesApplet.html.
o All the necessary files should be placed in a directory called
Question1_MiniProject.
[30 MARKS]
2. Consider the applet you wrote in Question 1. Now we want to convert this applet into a simple GUI with
similar functionality to the applet previously created.
􀀹 However, your GUI application should have a button called “Draw New Shapes” such that:
i. When you first start the GUI, all you should see is a frame with a WHITE background
and with the same size as before (i.e., 400x400 pixels), which also contains the button
mentioned above (located at the bottom of the frame).
ii. Each time you click the button “Draw New Shapes”, a random number of
rectangles and triangles should then be drawn and information about them printed, as
specified in Question 1. [Note: This means that, before a new set of shapes is displayed,
the background of the frame should be repainted.]
􀀹 You should, wherever possible, reuse the code you wrote for Question 1.
􀀹 All the necessary files (including any reused files from Question 1) should be placed in a
directory called Question2_MiniProject.
[10 MARKS]
Please remember that all your submitted programs must
include internal comments and Javadoc comments!有兴趣者联系我,QQ85936947,辛苦费没有问题的