package my_project;
public class my_first_class {
public static void main(String[] args) {
// TODO Auto-generated method stub
Point p1 = new Point();
p1.setX(8.0);
p1.setY(9.0);
Circle c1 = new Circle();
c1.setCentre(p1);
c1.setRadius(1.0);//设置c1的半径
System.out.println("圆心(x,y)= " + "(" + c1.getCentre().getX() + "," +
+ c1.getCentre().getY() + ")");
System.out.println("圆的半径 = " + c1.getRadius());
System.out.println("圆的面积= " + c1.getArea());
System.out.println("圆的周长= " + c1.getCircleLong());
}
}
class Point{
private double x;
private double y;
public double getX()
{
return x;
}
public void setX(double x)
{
this.x=x;
}
public double getY()
{
return y;
}
public double setY(double y)
{
return this.y=y;
}
}
class Circle{
private Point centre;
private double radius;
final static double PI = 3.1415926;//PI常量(最终类变量)
public Point getCentre()
{
return centre;
}
public void setCentre(Point centre)
{
this.centre = centre;
}
public double getRadius()
{
return radius;
}
public void setRadius(double radius)
{
this.radius=radius;
}
public double getArea()
{
return PI*Math.pow(radius,2);
}
public double getCircleLong()
{
return 2*PI*radius;
}
}
构造学生类:
package hello; public class Student { String xm,xh,xb; Student(){ } public Student(String xm, String xh, String xb){ this.xm=xm; this.xh=xh; this.xb=xb; } public String getXm() { return xm; } public void setXm(String xm) { this.xm = xm; } public String getXh() { return xh; } public void setXh(String xh) { this.xh = xh; } public String getXb() { return xb; } public void setXb(String xb) { this.xb = xb; } public String toString() { return "Student [xm=" + xm + ", xh=" + xh + ", xb=" + xb + "]"; } public void Print() { System.out.println("Student [xm=" + xm + ", xh=" + xh + ", xb=" + xb + "]"); } }