当前位置: 代码迷 >> Java相关 >> [求助]简单的JAVA程序注释
  详细解决方案

[求助]简单的JAVA程序注释

热度:119   发布时间:2007-06-17 22:09:10.0
[求助]简单的JAVA程序注释

自己刚学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>

搜索更多相关的解决方案: JAVA  注释  

----------------解决方案--------------------------------------------------------

我是学文科的.
选修的JAVA..希望大家帮帮忙..


----------------解决方案--------------------------------------------------------
我也是新手,只看得懂一些..
PACKAGE 编程还不会啊.
----------------解决方案--------------------------------------------------------

----------------解决方案--------------------------------------------------------

刚学都写这么长的程序,厉害


----------------解决方案--------------------------------------------------------

package test.oo.shape;//一个包,在test文件夹中的oo文件夹中的shape存在MyShape的字节码.class文件

public abstract class MyShape //定义了一个抽象类
{

protected String name; //受保护的字符型变量

public abstract double getGirth();//抽象方法以下的3个抽象方法都没有方法体

public abstract double getArea();//抽象方法

public abstract String toString();//抽象方法

public String getName()//通过getName()方法获取name变量
{
return this.name;
}

public void setName(String name)//做了一个接口name可以由此处接收来自外部的值
{
this.name = name;
}
}
俺学的也不久~只能做做简单介绍


----------------解决方案--------------------------------------------------------
厉害 刚刚学的就能写这么多的 厉害 。。。。
----------------解决方案--------------------------------------------------------
哭了
刚学?
还是选修!~
----------------解决方案--------------------------------------------------------

.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); //输出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>")

以下就简单了.你慢慢体会吧


----------------解决方案--------------------------------------------------------
  相关解决方案