2018.12.10

定义一个点类Point,包含2个成员变量x、y分别表示x和y坐标,2个构造器Point()和Point(int x0,y0),以及一个movePoint(int dx,int dy)方法实现点的位置移动,创建两个Point对象p1、p2,分别调用movePoint方法后,打印p1和p2的坐标

int x0,y0;
	Point(){
		
	}
	Point(int x0,int y0){
	this.x0	= x0;
	this.y0 = y0;
	}

	
	void movePoint(int dx,int dy) {
		this.x0 = this.x0 + dx;
		this.y0 = this.y0 + dy;
		System.out.println(this.x0+" "+this.y0);
	}

int length,width;
	
	Rectangle(){
		
	}
	Rectangle(int length,int width){
		this.length = length;
		this.width = width;
	}
	double getArea() {
		return this.length*this.width;
//		System.out.println("矩形面积:"+ this.length*this.width);
	}
	double getPer() {
		return 2*(this.length+this.width);
//		System.out.println("矩形的周长:"+2*(this.length+this.width));
	}
	void showAll() {
		System.out.println("矩形的长为:"+this.length+" "+"矩形的宽为:"+this.width);
		System.out.println("矩形面积:"+this.getArea());
		System.out.println("矩形的周长:"+this.getPer());
	}

char color;
	int cpunum;
	
	LapTop(){
		
	}
	LapTop(char color,int cpunum){
		this.color = color;
		this.cpunum = cpunum;
	}
	void aLapTop(char color,int cpunum) {
		this.color = color;
		this.cpunum = cpunum;
		System.out.println("笔记本颜色:"+this.color+" "+"笔记本cpu:"+this.cpunum);
	}
	char acolor() {
		return color;
	}
	
	int acpunum() {
		return cpunum;
	}
	
	
	void  LapTopshow() {
		System.out.println("笔记本颜色:"+acolor());
		System.out.println("笔记本cpu:"+acpunum());
	}

public static void main(String[] args) {
		LapTop l1 = new LapTop();
		l1.aLapTop('黄',20);
		LapTop l2 = new LapTop('绿',32);
		l2.LapTopshow();
	}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值