学习内容以圆类 Circle 及立体图形类 Solid 为基础设计圆锥类 Cone

代码示例:

import java.util.Scanner;

class Point4{
private double x;
private double y;
public Point4(double x,double y) {
this.x=x;
this.y=y;
System.out.println("Point Constructor run");
}
public void setX(double x) {//设置x坐标
this.x=x;
}
public double getX(){//返回x坐标
return x;
}
public void setY(double y) {//设置y坐标
this.y=y;
}
public double getY(){//返回y坐标
return y;
}
public void show() {//显示点的坐标
System.out.println("Point(X="+x+",Y="+y+")");
}
}
abstract class Plane4 extends Point4{
public Plane4(double x, double y) {
super(x, y);
}
double length() {
return 0;
}
double area() {
return 0;
}
}
class Circle2 extends Plane2 {

public Circle2(double x, double y,double radius) {
super(x,y);
this.x=x;
this.y=y;
this.radius=radius;
System.out.println("Circle Constructorrun");
}

private double x;
private double y;
final double PI=3.14159;
private double radius;
public void setX(double x) {//设置x坐标
this.x=x;
}
public final double getX(){//返回x坐标
return x;
}
public void setY(double y) {//设置y坐标
this.y=y;
}
public final double getY(){//返回y坐标
return y;
}
public void setR(double r) {
radius=r;
}
public final double getR() {
return radius;
}
public final void show() {
System.out.println("Circle(Point("+x+","+y+"),Radius="+radius+")");
}
public final double area() {
double area=PI*radius*radius;
System.out.println("Area="+area);
return 0;
}
public final double length() {
double length=2*PI*radius;
System.out.println("Length="+length);
return 0;
}
}
abstract class Solid1 extends Circle{
private double x;
private double y;
private double radius;
public Solid1(double x, double y, double radius) {
super(x, y, radius);
this.x=x;
this.y=y;
this.radius=radius;
}
public double volume() {//计算体积
return 0;
}
public double s_Area() {//计算表面积
return 0;
}
}
public class Cone extends Solid1{

private double x;
private double y;
private double radius;
private double height;
public void setX(double x) {//设置x坐标
this.x=x;
}
public void setY(double y) {//设置y坐标
this.y=y;
}
public void setR(double r) {
radius=r;
}
public void setH(double height) {
this.height=height;
}
public double getH() {
return height;
}
public Cone(double x, double y, double radius,double height) {
super(x, y, radius);
this.x=x;
this.y=y;
this.radius=radius;
this.height=height;
System.out.println("Cone Constructorrun");
}
public final void show() {
System.out.println("Cone(Circle(Point("+x+","+y+"),Radius="+radius+"),Height="+height+")");
}
public final double s_Area() {
double l=Math.sqrt(radius*radius+height*height);
double sarea=PI*radius*(radius+l);
System.out.println("s_Area="+sarea);
return 0;
}
public final double volume() {
double volume=(1.0/3.0)*PI*radius*radius*height;
System.out.println("Volume="+volume);
return 0;
}

public static void main(String[] args) {
double h;
System.out.println("请输入h:");
Scanner sc=new Scanner(System.in);
h=sc.nextDouble();
Cone co1=new Cone(1,2,3,4);
Cone co2=co1;
co1.show();
System.out.println();
co1.area();
co1.length();
co1.s_Area();
co1.volume();
System.out.println("............................................................................................");
co2.setH(h);
co2.show();
System.out.println();
co2.area();
co2.length();
co2.s_Area();
co2.volume();

}

}

运行截图:

明天任务异常处理

最新文章

  1. WCF学习之旅—WCF服务部署到IIS7.5(九)
  2. Python – locals和globals
  3. 2013 ACM-ICPC长沙赛区全国邀请赛——Bottles Arrangement
  4. ios专题 - openSSL
  5. JavaScript--我发现!原来你是这样的JS(1)
  6. 郑厂长系列故事——排兵布阵 hdu4539(状态压缩DP)
  7. win10 uwp 验证输入 自定义用户控件
  8. 关于Windows下程序执行的说明
  9. DLL简单分析与调用方法
  10. iOS原生实现二维码拉近放大
  11. C# 程序打包成安装项目
  12. Hdu1054 Strategic Game(最小覆盖点集)
  13. C++ template —— 模板中的名称(三)
  14. php下载文件,解压文件,读取并写入新文件
  15. Linux 文件系统的目录定义
  16. VS2010/MFC编程入门之二十五(常用控件:组合框控件Combo Box)
  17. 揭秘:C++编译器的函数编译流程
  18. CSS单位-长度
  19. XaaS简介(关于IssS,PaaS以及SaaS)
  20. mahout相关介绍

热门文章

  1. Centos7 离线安装 KVM,并安装 Csr1000v
  2. 腾讯云+社区开发者大会开启报名,WeGeek 邀你一起聊聊小程序
  3. 移动端的vw px rem之间换算
  4. C#委托、多播委托极简案例,一看就懂
  5. EMS恢复禁用邮箱
  6. Ubuntu安装开发者平台Backstage
  7. 学习打卡——docker部署
  8. Java学习day25
  9. mysql组提交
  10. 2021.11.11 EXKMP