java高手进类的继承问题

.分别编写两个类Point2D,Point3D来表示二维空间和三维空间的点,使之满足下列要求:
(1) Point2D有两个整型成员变量x, y (分别为二维空间的X,Y方向坐标),Point2D的构造方法要实现对其成员变量x, y的初始化。
(2)Point2D有一个void型成员方法offset(int a, int b),它可以实现Point2D的平移,有一个void型的draw()方法,实现对点的画法(这里可以用打印替代)
(3)Point3D是Point2D的直接子类,它有有三个整型成员变量x,y,z (分别为三维空间的X,Y,Z方向坐标),Point3D至少有两个构造方法:Point3D(int x,int y,int z)和Point3D(Point2D p,int z),两者均可实现对Point3D的成员变量x, y,z的初始化。
(4)Point3D有一个void型成员方法offset(int a, int b,int c),该方法可以实现Point3D的平移,也有一个draw方法,实现对Point3D的输出。
(5)在主类中实例化两个Point2D的对象p2d1,p2d2,测试它们的属性和功能,并打印出它们之间的距离,再实例化两个Point3D的对象p3d1,p3d2,,测试它们的属性和功能,并打印出它们之间的距离,并打印出他们之间的距离。
(6)要求在子类的构造函数中,通过super显示的调用父类的构造函数进行对象创建时属性的初始化
(7)要求覆盖toString()方法,个性化每个类的描述信息
(8)要求通过为Point2D和Point3D设置不同的Package,以及修改对应的成员限定权限,测试并掌握子类的继承性规则。
多少?

哈哈,我来啦!如果有看不懂的给我留言啊!(draw的要求不明白,所以draw方法里面的代码没写,你把要求重新描述一下,我帮你重写一下)
Point2D的代码:

package com.m;
public class Point2D
{
private int x;
private int y;

public Point2D(int x, int y)
{
this.x=x;
this.y=y;
}
public void offset(int a, int b)
{
x=x+a;
y=y+b;
}

public void draw()
{
}

public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

Point3D的代码:
package com.n;

import com.m.Point2D;
public class Point3D extends Point2D
{
private int z;

public Point3D(int x, int y, int z)
{
super(x,y);
this.z=z;
}

public Point3D(Point2D p, int z)
{
super(p.getX(), p.getY());
this.z=z;
}

public void offset(int a, int b,int c)
{
super.offset(a, b);
z=z+c;
}

public void draw()
{

}

public int getZ() {
return z;
}

public void setZ(int z) {
this.z = z;
}

public String toString()
{
return "Point3D:[x :"+getX()+" y :"+getY()+" z :"+getZ()+"]";
}
}

TestPoint代码:
import com.m.Point2D;
import com.n.Point3D;

public class TestPoint {

public static void main(String[] args)
{
double result;
int x,y,z;
Point2D p2d1,p2d2;
p2d1=new Point2D(1,2);
p2d2=new Point2D(3,4);
x=p2d1.getX()-p2d2.getX();
y=p2d1.getY()-p2d2.getY();
result=Math.sqrt(x*x+y*y);
System.out.println("p2d1与p2d2之间的距离为"+result);

Point3D p3d1,p3d2;
p3d1=new Point3D(1,2,3);
p3d2=new Point3D(4,5,6);
x=p3d1.getX()-p3d2.getX();
y=p3d1.getY()-p3d2.getY();
z=p3d1.getZ()-p3d2.getZ();
result=Math.sqrt(x*x+y*y+z*z);
System.out.println("p3d1与p3d2之间的距离为"+result);
}

}
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-05-25
貌似的确不难。30分足够了,等会有时间了帮你写
第2个回答  2010-05-25
你这道题分数给的太少了,你多给点分我就帮你哈!

起码100

先给部分代码你

基本框架帮你搭建好了

package com.isoftstone;

/**
* copyright Founder 2010
* @date 2010/05/25 V1.0新规作成
* dateタグの第二行目のコメント
* @author zenghz
* @version V1.0
* @brief 二维空间の定义
* @since 1.0
*/
public class Point2D
{
/**
* 二维空间的X方向坐标
*/
private int x;
/**
* 二维空间的Y方向坐标
*/
private int y;

/**
* 实现Point2D的平移
* @param a
* @param b
* @return
*/
public void offset(int a, int b)
{

}

/**
*对点的画法
*/
public void draw()
{

}

/**
* @return x
*/
public int getX()
{
return x;
}
/**
* @param x セットする x
*/
public void setX(int x)
{
this.x = x;
}
/**
* @return y
*/
public int getY()
{
return y;
}
/**
* @param y セットする y
*/
public void setY(int y)
{
this.y = y;
}

}

package com.isoftstone;

/**
* copyright Founder 2010
* @date 2010/05/25 V1.0新规作成
* @author zenghz
* @version V1.0
* @brief 三维空间の定义
* @since 1.0
*/
public class Point3D extends Point2D
{
/**
* 三维空间的X方向坐标
*/
private int x;
/**
* 三维空间的Y方向坐标
*/
private int y;
/**
* 三维空间的Z方向坐标
*/
private int z;

public Point3D(int x,int y,int z)
{

}

public Point3D(Point2D p,int z)
{

}

public void offset(int a, int b,int c)
{

}

/**
*对点的画法
*/
public void draw()
{

}

/**
* @return x
*/
public int getX()
{
return x;
}
/**
* @param x セットする x
*/
public void setX(int x)
{
this.x = x;
}
/**
* @return y
*/
public int getY()
{
return y;
}
/**
* @param y セットする y
*/
public void setY(int y)
{
this.y = y;
}
/**
* @return z
*/
public int getZ()
{
return z;
}
/**
* @param z セットする z
*/
public void setZ(int z)
{
this.z = z;
}

}
第3个回答  2010-05-25
好多字,但貌似很简单
相似回答
大家正在搜