package work;
public class Point {
int x;
int y;
public Point(){
}
public Point(int x0,int y0){
this.x=x0;
this.y=y0;
}
public void movePoint(int dx,int dy){
System.out.println("移动前的坐标为:"+x+","+y);
System.out.println("移动的量为:"+dx+" "+dy);
this.x +=dx;
this.y +=dy;
System.out.println("移动后的坐标为:"+this.x+","+this.y);
}
}
package work;
public class Test {
public static void main(String[] args) {
Point p1=new Point(1,2);
Point p2=new Point(3,4);
p1.movePoint(p2.x, p2.y);
}
}
package work;
public class Rectangle {
int length;
int width;
public Rectangle(int length,int width){
this.length=length;
this.width=width;
}
public int getArea(int length,int width){
return this.length*this.width;
}
public int getPer(int length,int width){
return (this.length+this.width)*2;
}
public void showAll(int length,int width){
System.out.println("矩形的长为:"+length+"矩形的宽为:"+width);
System.out.println("矩形的面积为:"+getArea(length,width));
System.out.println("矩形的周长为:"+getPer(length,width));
}
}
package work;
public class Test {
public static void main(String[] args) {
Rectangle r=new Rectangle(1,2);
r.showAll(r.length, r.width);
}
}
package work;
public class Notebook {
private char color;
private int cpu;
public Notebook(){
}
public Notebook(char color,int cpu){
this.color=color;
this.cpu=cpu;
}
public char getColor(){
return color;
}
public int getCpu(){
return cpu;
}
public void setColor(char color){
this.color=color;
}
public void setCpu(int cpu){
this.cpu=cpu;
}
public void show(){
System.out.println("笔记本电脑的颜色是:"+getColor()+"笔记本的cpu是:"+getCpu());
}
}
package work;
public class Test {
public static void main(String[] args) {
Notebook n=new Notebook();
n.show();
Notebook n2=new Notebook('蓝',1);
n2.show();
}
}