JAVA题目~圆柱体类Cylinder——类的组合 Exp03-6

Exp03-圆柱体类Cylinder——类的组合。

【问题描述】已知圆柱体Cylinder类由底面圆心(Point类的对象)、底面半径,高等成员组成,圆柱体底面圆平行于XY轴构成的平面。编写Java程序,输入底面圆心floorCenter的坐标(x,y,z)、底面半径radius和高height,构造一个圆柱体对象cylinder。
输出圆柱体的底面积floorage、表面积superficialArea(两个底的面积与侧面积之和)、体积volume,以及圆柱体中心点的坐标cylinderCenter(如图1中的k的位置)。如:底面圆心floorCenter为(6,5,0),底面半径raidus为3,圆柱体高height为10。输入输出格式,请参考下面的样例;所有输出数据,均保留到小数点后第3位。
 

【样例输入1】
6 5 0 3 10
【样例输出1】
Please enter the x, y and z coordinates of the floor circle center, the radius and height of the cylinder:
6 5 0 3 10
Floorage=28.274
Superficial area=245.044
Volume=282.743
Cylinder center coordinates are (6.000,5.000,5.000)


【样例输入2】
3 5 7 4 9
【样例输出2】
Please enter the x, y and z coordinates of the floor circle center, the radius and height of the cylinder:
3 5 7 4 9
Floorage=50.265
Superficial area=326.726
Volume=452.389
Cylinder center coordinates are (3.000,5.000,11.500)

 

import java.util.Scanner;
class Point{
	private double x,y,z;

	public Point(double x, double y, double z) {
		super();
		this.x = x;
		this.y = y;
		this.z = z;
	}
	public Point()
	{
		this(0,0,0);
	}
	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	public double getZ() {
		return z;
	}
	public void setZ(double z) {
		this.z = z;
	}
	@Override
	public String toString() {
		String str=String.format("(%.3f,%.3f,%.3f)",x,y,z);
		return str;
	}
	
}
class Cylinder{
	private Point floorCenter ;
	private double floorRaidus;
	private double floorHeight;
	public Cylinder(Point floorCenter, double floorRaidus, double floorHeight) {
		super();
		this.floorCenter = floorCenter;
		this.floorRaidus = floorRaidus;
		this.floorHeight = floorHeight;
	}
	public Point getFloorCenter() {
		return floorCenter;
	}
	public void setFloorCenter(Point floorCenter) {
		if(floorCenter == null)
			this.floorCenter = floorCenter;
		else
			System.out.println("The floor center object is null,can't assign again!");
	}
	public double getFloorRaidus() {
		return floorRaidus;
	}
	public void setFloorRaidus(double floorRaidus) {
		this.floorRaidus = floorRaidus;
	}
	public double getFloorHeight() {
		return floorHeight;
	}
	public void setFloorHeight(double floorHeight) {
		this.floorHeight = floorHeight;
	}
	public double getFloorage()
	{
		return Math.PI*floorRaidus*floorRaidus;
		
	}
	public double getSuperficial_area()
	{
		return 2*getFloorage()+2*Math.PI*floorRaidus*floorHeight;
	}
	public double getVolume()
	{
		return getFloorage()*floorHeight;
	}
	public Point getCylindeCenter()
	{
		return new Point(floorCenter.getX(),floorCenter.getY(),floorCenter.getZ()+floorHeight/2);
	}
}
public class Classcombination {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		System.out.printf("Please enter the x, y and z coordinates of the floor circle center, the radius and height of the cylinder:\n");
		double x=sc.nextDouble();
		double y=sc.nextDouble();
		double z=sc.nextDouble();
		double radius=sc.nextDouble();
		double height=sc.nextDouble();
		sc.close();
		Cylinder cylinder=new Cylinder(new Point(x,y,z), radius, height);
		System.out.printf("Floorage=%.3f\n",cylinder.getFloorage());
		System.out.printf("Superficial area=%.3f\n",cylinder.getSuperficial_area());
		System.out.printf("Volume=%.3f\n",cylinder.getVolume());
		System.out.println("Cylinder center coorinates are "+cylinder.getCylindeCenter());
	}
}

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值