自己刚学JAVA..超级领悟不了..
老师的作业.希望有人进来帮帮忙..把源程序后面做个注释..
1.package test.oo.shape;
public abstract class MyShape
{
protected String name;
public abstract double getGirth();
public abstract double getArea();
public abstract String toString();
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
}
2.package test.oo.shape;
public class Rectangle extends MyShape
{
private double length;
private double width;
public static final String SIDEERR = "长方形的长和宽必须大于0!";
public Rectangle()
{
init();
}
public Rectangle(double a, double b)
{
if ((a <= 0) || (b <= 0))
{
System.err.println(SIDEERR);
init();
}
else
{
this.length = a;
this.width = b;
}
}
private void init()
{
this.length = 5;
this.width = 4;
}
public double getGirth()
{
return (this.length + this.width) * 2;
}
public double getArea()
{
return this.length * this.width;
}
public String toString()
{
return "矩形的名字是:" + this.name + ",长为" + this.length + ",宽为" + this.width;
}
public double getLength()
{
return length;
}
public void setLength(double length)
{
if (length > 0)
{
this.length = length;
}
else
{
System.err.println(SIDEERR);
}
}
public double getWidth()
{
return width;
}
public void setWidth(double width)
{
if (width > 0)
{
this.width = width;
}
else
{
System.err.println(SIDEERR);
}
}
public static void main(String[] args)
{
Rectangle test = new Rectangle();
test.setName("myRectangle");
System.out.println( test.toString());
System.out.println("矩形的周长是:" + test.getGirth());
System.out.println("矩形的面积是:" + test.getArea());
}
}
3.<SCRIPT LANGUAGE="JavaScript">
var total = 0
var play = false
function display(element) {
var now = new Date()
if (!play) {
play = true
startTime = now.getTime()}
if (now.getTime() - startTime > 20000) {
element.checked = !element.checked
return
}
if (element.checked)
total++
else
total--
element.form.num.value = total
}
function restart(form) {
total = 0
play = false
for (var i = 1; i <= 100; ++i) {
form.elements[i].checked = false
}
}
</SCRIPT>
<CENTER>测试你在20秒内能点击多少个框!</CENTER>
<SCRIPT LANGUAGE="JavaScript">
document.write("<FORM><CENTER>")
document.write('<INPUT TYPE="text" VALUE="0" ');
document.write('NAME="num" SIZE=10 onFocus="this.blur()"><BR>')
document.write("<HR SIZE=1 WIDTH=40%>")
for (var i = 0; i < 10; ++i) {
for (var j = 0; j < 10; ++j) {
document.write('<INPUT TYPE="checkbox" ');
document.write('onClick="display(this)">')}
document.write("<BR>")}
document.write("<HR SIZE=1 WIDTH=40%>")
document.write('<INPUT TYPE="button" VALUE="开始" ');
document.write('onClick="restart(this.form)">')
document.write("</CENTER></FORM>")
</SCRIPT>