第五次实验的.pdf
文本预览下载声明
1. 设计
(1)形状接口、(2)积木块抽象类、(3)三角形类、正方形类、圆形类和矩形类,
其中(2)实现了(1),(3)继承了(2 ),然后编写主函数分别定义它们的对象,并显示其值。
2. package shape;
3.
4. public interface 形状 {
5. int 边 =0;
6. void 面积();
7.
8. }
package shape;
public abstract class 积木块 implements 形状 {
int 边=0;
public abstract void 面积 ();
}
package shape;
public class 三角形 extends 积木块{
int 边=3;
int a=0,b=0,c=0;
三角形()
{
this .a=0;
this .b=0;
this .c=0;
this .边=3;
}
三角形(int a,int b,int c)
{
this .a=a;
this .b=b;
this .c=c;
}
@Override
public void 面积() {
// TODO Auto-generated method stub
int p=(a+b+c)/3;
System.out .println(面积为+Math.sqrt ((p-a)*(p-b)*(p-c)));
}
}
package shape;
public class 圆 extends 积木块{
int 边=1;
int 半径=0;
圆()
{
this .半径=0;
this .边=1;
}
圆(int r)
{
this .半径=r;
}
@Override
public void 面积() {
// TODO Auto-generated method stub
System.out .println(面积为 :+Math.PI*半径*半径);
}
}
package shape;
public class 矩形 extends 积木块 {
int 边=4;
int a=0,b=0;
矩形()
{
this .a=0;
this .b=0;
this .边=3;
}
矩形(int a,int b)
{
this .a=a;
this .b=b;
}
@Override
public void 面积() {
// TODO Auto-generated method stub
System.out .println(面积为+a*b);
}
}
package shape;
public class Main {
public static void main(String args[])
{
三角形 t1=new 三角形(1,3,3);
圆 c1=new 圆(5);
矩形 s1=new 矩形(2,4);
t1.面积();
c1.面积();
s1.面积();
}
}
2.分别建立两个线程,产生并显示[100,10000]和[20000,30000]之间的随机数各10000 个,并
分别求和显示出来。
package thread;
import java.util.Random;
public class Thr {
public static void main(String args[])
{
Thread1 t1=new Thread1(null);
Thread2 t2=new Thread2();
显示全部