圆锥体的表面积和体积计算
最编程
2024-07-05 22:38:40
...
1. 定义Area 和 Volume 连个接口
2. 计算圆锥的表面积和体积
3. 按体积的大小判断圆锥的大小
package zuo_ye4;
import java.util.Scanner;
import java.util.ArrayList;
public class Cone implements Area, Volume {
double r; //底面圆的半径
double r1; //侧面扇形的母线
double l; // 底面圆的周长
double h; //圆锥底面圆到顶点的距离(高)
double s; //圆锥表面积
double v; // 圆锥体积
public double getR1() {
return r1;
}
public void setR1(double r1) {
this.r1 = r1;
}
public double getR() {
return r;
}
public double getV() {
return v;
}
public void setV(double v) {
this.v = v;
}
public void setR(double r) {
this.r = r;
}
public double getL() {
return l;
}
public void setL(double l) {
this.l = l;
}
public double getH() {
return h;
}
public void setH(double h) {
this.h = h;
}
public double getS() {
return s;
}
public void setS(double s) {
this.s = s;
}
@Override
public void area(int k) {
// 底部面积+侧面积
// (1)底面圆面积 r*r*PI (2) 底面圆的周长 2*r*PI (3) 侧面积 1/2*l*R
int i=1;
System.out.println("第 "+k+" 个圆锥");
double s1 = this.r * this.r * this.PI;
this.l=this.r*PI*2;
double s2 = this.l*this.r1;
this.s=s1+s2;
System.out.printf("底面圆面积为: %.2f\n",s1);
System.out.printf("圆锥侧面扇形积为: %.2f\n",s2);
System.out.printf("圆锥表面积为: %.2f\n",this.s);
}
@Override
public void volume() {
// 底面积 x 高 x 1/3
// 体积计算
double s1 = this.r * this.r * this.PI ;
this.v = (s1 *this.h)*1/3;
}
//体积比较VS打印体积
public void bvb(ArrayList<Cone> arr){
System.out.println("-------计算圆锥的体积-------");
Cone c =arr.get(1);
if (this.v==c.getV()){
System.out.printf("第一个圆锥的体积为: %.2f\n第二个圆锥的体积为: %.2f\n",this.v,c.getV());
System.out.println("提示: 两个圆锥相等");
}else if(this.v > c.getV()){
System.out.printf("第一个圆锥的体积为: %.2f\n第二个圆锥的体积为: %.2f\n",this.v,c.getV());
System.out.println("提示: 第一个圆锥大于第二个圆锥");
}else{
System.out.printf("第一个圆锥的体积为: %.2f\n第二个圆锥的体积为: %.2f\n",this.v,c.getV());
System.out.println("提示:第一个圆锥小于第二个圆锥");
}
}
public static void main(String[] args) {
ArrayList<Cone> arr = new ArrayList<>();
input(arr);
System.out.println("-------计算圆锥表面积-------");
int k =1;
for (Cone c1 :arr) {
c1.area(k);
c1.volume();
k++;
}
Cone c2=arr.get(0);
c2.bvb(arr);
}
public static void input(ArrayList<Cone> arr){
System.out.println("-------请输入圆锥的已知条件!!-------");
Scanner scan =new Scanner(System.in);
int i =1;
while(i<3) {
System.out.println("请输入第 "+i+" 圆锥的已知条件");
System.out.print("输入底部圆的半径 r :");
Cone c = new Cone();
double r = scan.nextDouble();
c.setR(r);
System.out.print("输入底部到圆锥顶点的高 h :");
double h = scan.nextDouble();
c.setH(h);
System.out.print("输入侧面扇形的母线 r1 :");
double r1 = scan.nextDouble();
c.setR1(r1);
arr.add(c);
i++;
System.out.println();
}
}
}
// 接口 面积
interface Area {
public static final double PI = 3.14;
public abstract void area(int k);
}
// 接口体积
interface Volume {
public abstract void volume();
}
上一篇: 圆锥体体积是圆柱体体积三分之一的简单证明
下一篇: 圆锥体计算
推荐阅读
-
FPGA 实现 PCIE 捕捉计算机视频到 SFP 光端口的 UDP 输出,基于 XDMA + GTX 架构,提供 4 套工程源代码和技术支持
-
[学习笔记] 利用多项式计算正弦和余弦近似值的快速方法。
-
计算机网络各层协议有哪些?计算机网络协议分析:从制定到实施,全面了解各层协议的作用和区别
-
MATLAB 计算和建模的常用函数:5.曲线拟合
-
新技术浪潮下的等效评估:云计算、物联网和大数据的挑战与机遇
-
Meta 推出支持多模态和边缘计算的 Llama 3.2 人工智能模型;OpenAI 首席技术官 Murati 宣布离职
-
在 Gitee 等 Linux 系统上备份云计算 git 的所有软件源和所有分支
-
10bit YUV(P010)的存储结构和处理-随着计算机处理信息的能力越来越厉害,这种能表现更高动态范围的图像存储格式将会逐渐成为主流,但是现在很多算法都不能直接处理 10bit 的 YUV ,都是先将其转换为 8bit YUV ,然后再进行处理,这实际上是丢弃了 10bit YUV 的图像高动态范围优势。 令人遗憾的是在渲染图像时,目前 OpenGL 也无法直接对 10bit YUV 进行渲染,也是需要先转换为 8bit YUV 。 接下来以一种常见的 10bit YUV (P010) 格式为例,介绍一下 10bit YUV 到 8bit YUV 的转换过程。 P010 最早是微软定义的格式,表示的是 YUV 4:2:0 的采样方式,也就是说 P010 表示的是一类 YUV 格式,它的内存排布方式可能是 NVNVYUYV12 。
-
【云解压】深入剖析ZIP文件格式——解析偏移计算与文件大小表示的ZIP32和ZIP64
-
解密腾云:云计算和大数据时代的网络技术(读书笔记1+2)