定义一个点类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;
}
double getPer() {
return 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();
}