首页 > 编程语言 > 详细

java 接口练习题6

时间:2016-05-26 18:41:23      阅读:158      评论:0      收藏:0      [点我收藏+]

定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)。要求如下:

1)可以生成具有特定坐标的点对象。

2)提供可以设置三个坐标的方法。

3)提供可以计算该“点”距原点距离平方的方法。

4)编写主类程序验证。

public class Point {
    private int a,b,c;
    Point (int a,int b,int c)
    {
        this.a=a;
        this.b=b;
        this.c=c;
    }
    public int getA() {
        return a;
    }
    public void setA(int a) {
        this.a = a;
    }
    public int getB() {
        return b;
    }
    public void setB(int b) {
        this.b = b;
    }
    public int getC() {
        return c;
    }
    public void setC(int c) {
        this.c = c;
    }
    public void Juli()
    {
        System.out.println("坐标"+a+","+b+","+c+"距离原点的距离的平方="+(a*a+b*b+c*c));
    }
    public static void main(String[] args) {
        Point p=new Point(2,2,2);
        p.Juli();
        p.setA(3);
        p.setB(5);
        p.setC(9);
        p.Juli();
    }

技术分享

java 接口练习题6

原文:http://www.cnblogs.com/jskbk/p/5531951.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!