java中set集合get方法吗_java中set和get方法

importjava.awt.Color;publicclassPoint{privateintx;privateinty;privateColormycolor;publicPoint(){}publicPoint(intx,inty){this.x=x;this.y=y;}publicPoint(intx,inty,Colormyco...

import java.awt.Color;

public class Point{

private int x;

private int y;

private Color mycolor;

public Point(){

}

public Point(int x,int y){

this.x=x;

this.y=y;

}

public Point(int x,int y,Color mycolor){

this.x=x;

this.y=y;

this.mycolor=mycolor;

}

//从这里开始

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;

}

public Color getColor() {

return color;

}

public void setColor(Color color) {

this.color = color;//到这里结束一定要有么,是在定义set和get方法么?

public int distance (Point another){

return (int)Math.sqrt((this.x-another.x)*(this.x-another.x)+(this.y-another.y)*(this.y-another.y));

}

public boolean equals(Point another){

return (this.x==another.x&&this.y==another.y)?true:false;

}

public String toString(){

return "("+x+","+y+")color:"+mycolor;

}

public static void main(String[] args){

Point A=new Point();

Point B=new Point(50,60);

Point C=new Point(100,200,Color.yellow);

System.out.println("B: "+B);

A.setX(100);

A.setY(200);

A.setColor(Color.yellow);

System.out.println("A :"+A);

System.out.println("A==B? "+A.equals(B));

System.out.println("A->B "+A.distance(B));

}

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值