JAVA 3道题 速度只今天啊答对的追加分

1.创建两个线程。每个线程进行5次循环,每次循环显示循环的次数和当前运行的线程名字,然后休眠一个随机时间。
2.编写一个Java应用程序,除了主类外,该程序中还有4个类:People,ChinaPeople,AmericanPeople和BeijingPeople类。要求如下:
(1)People类有访问权限是protected的double类型成员变量heigth和weigth,以及public void speakHello()、public void averageHeight()和public averageWeight()方法。
(2)ChinaPeople类是People的子类,新增了Public voidchinaGongu()方法。要求ChinaPeople重写父类的public void speakHello()、public void verageHeight()和public void averageWeight()方法。
(3)AmericanPeople类是People的子类,新增public void americanBoxing()方法。要求AmericanPeople重写父类的public void speakHello()、public void averageHeight()和public void averageWeight()方法。
(4)BeijingPeople类是ChinaPeople的子类,新增public void beijingOpera()方法。要求ChianPeople重写父类的public void speakHello()、public void averageHeight()和public void averageWeight()方法。
3.用main()创建一个类,令其在一个try块内产生Exception类的一个对象。在构造函数里,为Exception指定一个String参数。在catch从句内捕获违例,并打印出String参数。添加一个finally从句,用它打印一条消息,证明程序finally块运行过。
我就30分了.....没有人能帮下么

1.

public class SimpleThread extends Thread{
SimpleThread(String s){
super(s);
}
public void run(){
String name = this.getName();
for(int i = 1 ; i <= 5 ; i++){
System.out.println(name + "第" + i + "次输出!");
try {
sleep((int)(Math.random()*1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String [] args){
SimpleThread s1 = new SimpleThread("线程1");
SimpleThread s2 = new SimpleThread("线程2");
s1.start();
s2.start();
}
}

2.
class People {
double height,weight;
public void speakHello(){}
public void qverageHeight(){}
public void averageWeight(){}
}
class ChinaPeople extends People{
public void chinaGongu(){}
public void averageWeight(){
System.out.println("chinese weight!");
}
public void speakHello(){
System.out.println("chinees speaking!");
}
public void qverageHeight(){
System.out.println("chinese heght!");
}
}
class AmericanPeople extends People{
public void americanBoxing(){}
public void averageWeight(){
System.out.println("AmericanPeople weight!");
}
public void speakHello(){
System.out.println("AmericanPeople speaking!");
}
public void qverageHeight(){
System.out.println("AmericanPeople heght!");
}
}
class BeijingPeople extends People{
public void beijingOpera(){}
public void averageWeight(){
System.out.println("BeijingPeople weight!");
}
public void speakHello(){
System.out.println("BeijingPeople speaking!");
}
public void qverageHeight(){
System.out.println("BeijingPeople heght!");
}
}
3.
class StringException extends Exception{
String s;
StringException(String s){
this.s = s;
}
String getS(){
return s;
}
}
class TestString{
public TestString(String s) throws StringException{
if(s.equals("haha")){
throw new StringException(s);
}
}
}
public class ExampleException {
public static void main(String [] args){
try{
TestString ts = new TestString("haha");
}
catch(StringException se){
System.out.println("输入的数据有异常,不能取值"+se.getS());
}
finally{
System.out.println("finally 被运行!");
}
}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-12-06
1.你分数给太少了
2.每个问题都需要编码.. 太麻烦
3.为什么不去百度一下呢 虽然可能和你的问题不全一样 但是怎么也是差不多啊
相似回答