package h_m5_1;
import java.awt.Point;
/*
* 练习一
*/
public class Ponit01 {
private int x ;
private int y ;
public Ponit01() {
}
public Ponit01(int x, int y) {
super();
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "Ponit01 [x=" + x + ", y=" + y + "]";
}
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 void movePoint(int a,int b){
this.x=a;
this.y=b;
}
public static void main(String[] args) {
Ponit01 p1 = new Ponit01(2,3);
Ponit01 p2= new Ponit01();
p1.movePoint(5, 6);
System.out.println(p1);
p2.setX(8);
p2.setY(9);
System.out.println(p2);
p2.movePoint(1, 2);
System.out.println(p2);
}
}
package h_m5_1;
/*
* 练习二
*/
public class Reactangle {
private int width;
private int height;
public Reactangle(int width, int length) {
super();
this.width = width;
this.height = length;
}
public void getArea(){
System.out.println("矩形面积:"+width*height);
}
public void getZou(){
System.out.println("矩形的周长是:"+(width+height)*2);
}
public void getAll(){
getArea();
getZou();
System.out.println("宽:"+width+","+"高"+height);
}
public static void main(String[] args) {
Reactangle r = new Reactangle(5, 6);
r.getAll();
}
}
package h_m5_1;
/*
* 练习三
*/
public class Person {
int weight;
int height;
String name;
public Person() {
// TODO Auto-generated constructor stub
}
public Person(int weight, int height, String name) {
super();
this.weight = weight;
this.height = height;
this.name = name;
}
public void sayHello() {
System.out.println("Hello my name is"+name);
}
public static void main(String[] args) {
Person p= new Person(70, 175, "王兆明");
p.sayHello();
}
}