public class Java_3{ int x,y; ?//點(diǎn)的坐標(biāo) public Java_3() {} ?//無參數(shù)的構(gòu)造方法? ? ? ? //*********Found********? ? ? ? //帶兩個(gè)參數(shù)的構(gòu)造方法? ? ? ? public Java_3(int x,int y){this.x=x;this.y=y;} ?? ? ? ? //*********Found********? ? ? ? //帶一個(gè)參數(shù)的構(gòu)造方法? ? ? ? public Java_3(Java_3 p){System.out.println( p );} ? public Java_3 getLocation(){ ?//以對(duì)象的形式返回當(dāng)前點(diǎn)的位置? ? ? ? //*********Found********? ? ? ? ? ? //實(shí)例化一個(gè)Java_3對(duì)象p?? ? ? ? ? ? Java_3 p=null; ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? //*********Found********? ? ? ? ? ? //返回對(duì)象p? ? ? ? ? ? return p; ? ? ? ? } public int getX(){return x;} ?//返回點(diǎn)的橫坐標(biāo) public int getY(){return y;} ?//返回點(diǎn)的縱坐標(biāo) public void move(int x,int y){this.x = x;this.y = y;} ?//把當(dāng)前點(diǎn)移到新的位置(x,y)上 public String toString(){return "("+x+","+y+")";} ?//以(x,y)的格式返回點(diǎn)的位置 public void translate(int x,int y){this.x += x;this.y += y;} ?//在原有坐標(biāo)上分別增加x和y //主方法 public static void main(String args[]){? ? ? ? //*********Found********? ? ? ? ? ? ?//生成一個(gè)對(duì)象(5,5)? ? ? ? ? ? Java_3 p=new Java_3(5,5);?? ? ? ? ? ? System.out.println("x="+ p.x+" y="+ p.y);? ? ? ? ? ? System.out.println("Location is"+ p.toString()); ?//以(x,y)的方式打印坐標(biāo)的位置? ? ? ? ? ? //*********Found********? ? ? ? ? ? ?//在原有位置上增加(3,4)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??;? ? ? ? ? ? System.out.println("x="+ p.x+" y="+ p.y); ?//打印橫坐標(biāo)和縱坐標(biāo)的值? ? ? ? ? ? System.out.println("Location is"+ p.toString()); ? //以(x,y)的方式打印坐標(biāo)的位置 }}只能在下劃線處添加一行代碼,求各位大神指教
添加回答
舉報(bào)
0/150
提交
取消