浙江广播电视大学2007年秋季学期开放教育专科期末考试
《Java语言与面向对象程序设计基础》试题答案及评分标准
2008年1月
一、判断题(每小题2分,共20分)
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
× |
× |
√ |
√ |
√ |
√ |
× |
× |
× |
√ |
二、单项选择题(每小题2分,共40分)
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
A |
C |
D |
A |
A |
B |
B |
A |
C |
B |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
D |
B |
B |
A |
A |
C |
C |
A |
C |
D |
三、程序阅读题(每小题6分,共30分)
1 |
in Test! in Test! |
2 |
复制文件A.java到文件B.java |
3 |
x=6,t.y=1 x=7,t.y=1 |
4 |
5 |
5 |
integer |
四、编程题(10分)
public class Test
{
public static void main(String args[])
{ MyTriangle t=new MyTriangle(3.0,4.0,5.0);
System.out.println(t);
}
}
interface MyShape //接口定义(2分)
{
public abstract double getPerimeter();
public abstract double getArea();
}
class MyTriangle implements MyShape
{
double x,y,z;
double s;
MyTriangle(double t1,double t2, double t3) //构造方法(2分)
{
if(t1+t2>t3&&t1+t3>t2&&t2+t3>t1)
{
x=t1; y=t2; z=t3; s=(x+y+z)/2;
}
else
{
System.out.println("不能构成三角形");
System.exit(0);
}
}
public double getPerimeter()//求周长方法(2分)
{
return x+y+z;
}
public double getArea()// 求面积方法(2分)
{
return Math.sqrt(s*(s-x)*(s-y)*(s-z));
}
public String toString() // toString()(2分)
{
return "three sides:"+x+","+y+","+z+","+"perimeter="+getPerimeter()+",area="+getArea();
}
}