读书人

才学JAVA一般怎么安排程序代码的格式

发布时间: 2011-12-30 23:30:45 作者: rapoo

才学JAVA,一般如何安排程序代码的格式呢
下面是我做的一道作业题,我想大家把你们的排版方式给我看哈,我不知道该怎么排,不排好的话以后代码看起来就很杂乱...
class point{
protected int x,y;
public point(){
x=0;
y=0;
}
public point(int x,int y){
this.x=x;
this.y=y;
}
public int getX(){
return x;
}

public int getY(){
return y;
}

public void setX(int x){
this.x=x;
}

public void setY(int y){
this.y=y;
}
}

class Circle extends point{
protected int radius;
public Circle(int r,int x,int y){
super(x,y);
radius=r;
}
public Circle(){
radius=0;
}
public Circle(int radius){
this.radius=radius;
}
public int getRadius(){
return radius;
}
void area(){
System.out.println( "圆的面积: "+ Math.PI*radius*radius);
}
double A(){
return Math.PI*radius*radius;
}
}

class Cylinder extends Circle{
protected int height;
Cylinder(int x,int y,int radius,int height){
super(x,y,radius);
this.height= height;
}
Cylinder(){
height=0;
}
Cylinder(int H){
height=H;
}
int getHeight(){
return height;
}
void volume(){
System.out.println( "圆zhu的体积: "+A()*height);
}
}
class demo{
public static void main(String args[]){

Cylinder r1=new Cylinder(10,10,10,10);
System.out.println( "中心坐标: "+r1.x+ ", "+r1.y);
System.out.println( "半径: "+r1.radius);
System.out.println( "高: "+r1.height);
r1.volume();
}
}

[解决办法]
建议你用Eclipse,用Ctrl+Shift+F,自动调节代码的格式安排,看起来明白的多, 很方便

[解决办法]
class classname
{
mothed mothedname()
{
........
}
}
这样应该更清晰些
[解决办法]
个人习惯而已~

class ClassName{//ClassName第一个字母大写
private int aaaBbb;//变量,匈牙利命名法

public void methodName(){//methodName首字母小写,并且整体能看出来该方法的意义的
//........
}
}
[解决办法]
注释啊```兄弟`````

读书人网 >J2SE开发

热点推荐