急求JAVA高人帮忙

来源:百度知道 编辑:UC知道 时间:2024/06/10 11:27:07
请大家帮帮忙,我有急用,我愿意拿出我所有的分,谢谢大家了
Create an applet that draws a random number (as specified below) of rectangles and ovals 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 500 by 500 pixels with a BLUE background colour.
􀀹 Determine how many rectangles and ovals should be drawn. This should be a random integer
number:
a. between 0 and 2 for rectangles;
b. between 0 and 3 for ovals.
􀀹 All rectangles should be RED and all ovals should be GREEN.
􀀹 The size and measurements of the rectangles and ovals to be drawn should be as follows:
o Rectangles:
􀂃 The width and height should both be random integer numbers between 10
and 25.
􀂃 If the determined width and height numbers are the same, then this is not a
valid rectangle. Create the IllegalRectangleException class to signal

写一个applet。
要求:
1. applet的背景大小是500*500,蓝色。
2. 用Math.Random来获得两个随机数,一个在0到2之间,一个在0到3之间。0到2之间的数决定了你等一下要画的矩形数量,0-3则是椭圆的数量。
3. 矩形要用红色画,椭圆则是绿色。矩形的长宽也是随机生成,大小要在10到25之间,并且不能相同,一旦相同就抛出IllegalRectangleException (这个异常要自己写)。画出了矩形之后要在矩形的下方写出矩形的长宽、面积和周长,精确到小数点后两位(假设单位是厘米)。椭圆长宽也一样要随机生成,大小则是在10到50之间,可以相同,一样在图形的下方写出长宽、面积和周长,精确到小数点后两位。
4. 图形按照列的形式排列画出(也就是说一列一列画出,不是一行一行画出),并且确保不会发生重叠的现象。画完再统计分别写出画了多少个矩形和多少个椭圆。

具体的类文件定义限制:
1. 写一个几何图形GeometricShape类,这是你下面要写的矩形类Rectangle 和椭圆类Oval的父类。
2. 分别写出矩形类Rectangle 和椭圆类Oval,实现两个方法,即计算面积的calculateArea() 和 计算周长的calculatePerimeter()。(个人建议是将这两个方法和面积、周长变量定义在父类GeometricShape,然后在子类里面覆盖重写,因为所有的几何图形都可以有面积和周长的嘛~~,然后再于矩形类Rectangle 和椭圆类Oval之中定义两个个变量,即长、宽,便于等下用Graphics的fillOval(int x, int y, int width, int height)来画图形)
3. IllegalRectangleException异常的定义,直接继承于Exception,覆盖无参数的那个构造函数,在里面调用super("非法的矩形长宽定义");就行了。
4. 最后就是写applet啦,名字叫PrintAndMeasureShapes。要求就按上面的做。最后写一个MyShapesApplet.html来显示调用这个applet。

代码私下给~~<