每日一篇代码系列(9)

时间:2020-12-04 14:38:09   收藏:0   阅读:22
 1 class Cylinder {
 2   private double radius;
 3   private int height;
 4   private double pi=3.14;
 5   private String color;
 6   public double setCylinder(double r,int h) {
 7     radius=r;
 8     height=h;
 9     return r+h;
10   }
11   public void setCylinder(String str) {
12     color=str;
13   }
14   public void show() {
15     System.out.println("颜色为:"+color);
16   }
17   double area() {
18     return pi*radius*radius;
19   }
20   double volume() {
21     return area()*height;
22   }
23 }
24 public class C1_1 {
25   public static void main(String[] args) {
26     double r_h;
27     Cylinder volu=new Cylinder();
28     r_h=volu.setCylinder(2.5,5);
29     volu.setCylinder("红色");
30     System.out.println("半径和高之和="+r_h);
31     System.out.println("体积="+volu.volume());
32     volu.show();
33   }
34 }

 

原文:https://www.cnblogs.com/ljydbk/p/14085353.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!