Chinaunix首页 | 论坛 | 博客
  • 博客访问: 127226
  • 博文数量: 28
  • 博客积分: 2431
  • 博客等级: 大尉
  • 技术积分: 321
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-29 18:40
文章分类

全部博文(28)

文章存档

2011年(3)

2010年(6)

2009年(7)

2008年(12)

分类: Java

2008-10-13 09:50:11

import java.io.*;
class Point                         //点类
{
  protected double x,y;
  public Point()                    //无参数构造方法
  {
    this.x=0;
    this.y=0;
  }
  public Point(double x,double y)         //有参数构造方法
 {
   this.x=x;
   this.y=y;
 }
 public void setX(double x)                   //设置坐标 X
 {
    this.x=x;
 }
 public void setY(double y)                   //设置坐标 Y
 {
    this.y=y;
 }
 public double getX()                         //获取坐标 X
 {
   return this.x;
 }
 public double getY()                         //获取坐标 Y
 {
   return this.y;
 }
}
 class Circle extends Point                //圆类
 {
   protected double r;
   public Circle() {}                      //无参数构造方法
   public Circle(double x,double y,double r)     //有参数构造方法
   {
     super(x,y);
     this.r=r;
   }

   public void setR(double r)           //设置半径R
   {
     this.r=r;
   }

   public double getR()                //获取半径R
   {
     return this.r;
   }
   public double area()                //获取圆面积
   {
     double s=0;
     s=Math.PI*this.r*this.r;
     return s;
   }
 }
class Cylinder extends Circle
 {
    protected double h;
    public Cylinder(){}                  //无参数构造方法
    public Cylinder(double x,double y,double r,double h)//有参数构造方法
    {
      super(x,y,r);
      this.h=h;
    }
    public void setH(double h)           //设置高度H
  {
    this.h=h;
  }
  public double getH()                   //获取高度H
  {
    return this.h;
  }
  public double cube()                   //获取体积
  {
     
      return area()*h;
     
      //补充完整
   }
 }
 //定义一个ex6主类,在其main()方法中通过输入参数(x,y,r)和(x,y,r,h)
 //的方式声明并实例化一个Circle对象和2个Cylinder对象,并输出其对应的基本
 //信息(圆[x,y,r,s];圆柱体[x,y,r,h, V])的值
public class ex6     //主类
{
 public static void main(String args[]) throws IOException
 {
   BufferedReader buf;
   buf=new BufferedReader(new InputStreamReader(System.in));
   String  str_x,str_y,str_r,str_s,str_h,str_v;
   System.out.println("please input x,y,r,h:");
   str_x=buf.readLine();
   str_y=buf.readLine();
   str_r=buf.readLine();
   str_h=buf.readLine();
   //str_s=buf.readLine();
   //str_v=buf.readLine();
   double x=Double.parseDouble(str_x);
   double y=Double.parseDouble(str_y);
   double r=Double.parseDouble(str_r);
   //double s=Double.parseDouble(str_s);
   double h=Double.parseDouble(str_h);
   //double v=Double.parseDouble(str_v);
   Point p1=new Point();
   p1.setX(x);
   p1.setY(y);
   Circle c1=new Circle();
   c1.setR(r);
   Cylinder yz = new Cylinder(x,y,r,h);
   yz.setH(h);
   Cylinder yz1 = new Cylinder(5,6,3,4);
   yz1.setH(h);
   System.out.println("first:园心坐标:("+yz.getX()+","+yz.getY()+") 半径:"+yz.getR()+" 高:"+yz.getH());
   System.out.println("底面积:"+c1.area()+"体积:"+yz.cube() );
   System.out.println("second:园心坐标:("+yz1.getX()+","+yz1.getY()+") 半径:"+yz1.getR()+" 高:"+yz1.getH());
   System.out.println("体积:"+yz1.cube() );
  
  

   //补充完整
 }
}

阅读(1063) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~