源气泡 2022-10-07 20:14 采纳率: 88.9%
浏览 25
已结题

这怎么写呀,这是要求,我觉得没错的呀

img


主要代码
import java.util.Scanner;class Circle {
public double r;
public double get_r(double r){
return r; }
public void set_r(double r) {
this.r= r; }
public double getArea() {
return Math.PIrr; }
public double getPeriometer() {
return 2Math.PIr; }
}
class YuanZhu extends Circle{
private Circle bottom;
private double h;
public YuanZhu() {
super(); }
public YuanZhu(Circle bottom) {
super();
this.bottom = bottom; }
public YuanZhu(double h) {
super();
this.h = h; }
public YuanZhu(Circle bottom,double h) {
super();
this.bottom = bottom;
this.h = h; }
public double getVolume() {
return this.bottom.getArea()*h; }
public double getBiaoMian() {
return this.bottom.getArea()*2+this.bottom.getPeriometer()*h; }}
public class test1 {
public static void main(String[] args) {
double r=10,h=20;
Circle c1 = new Circle();
YuanZhu Y1 = new YuanZhu();
System.out.printf("圆的面积:");
c1.getArea();
System.out.printf("圆的体积:");
c1.getPeriometer();
System.out.printf("圆柱的表面积:");
Y1.getBiaoMian();
System.out.printf("圆柱的体积:");
Y1.getVolume(); }}

img


getVolume()函数就不空 getBiaoMian()怎么就空呢

  • 写回答

1条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-10-07 20:31
    关注

    你得给他赋值啊,没有bottom的值不为空才怪了

    img

    
    public static void main(String[] args) {
            double r=10,h=20;
            Circle c1 = new Circle();
            c1.set_r(r);
             YuanZhu Y1 = new YuanZhu(c1,h);
            System.out.printf("圆的面积:"+c1.getArea());
    
            System.out.printf("圆的体积:"+c1.getPeriometer());
    
            System.out.printf("圆柱的表面积:"+ Y1.getBiaoMian());
    
            System.out.printf("圆柱的体积:"+Y1.getVolume());
             }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月15日
  • 已采纳回答 10月7日
  • 创建了问题 10月7日

悬赏问题

  • ¥15 oracle数据库查询语句问题
  • ¥15 有没有c++绘制算法的佬们吗救孩一下
  • ¥15 android 蓝牙闪退
  • ¥15 绝缘子污秽comsol仿真参数
  • ¥15 Fatal error in Process MEMORY
  • ¥15 labelme生成的json有乱码?
  • ¥30 arduino vector defined in discarded section `.text' of wiring.c.o (symbol from plugin)
  • ¥20 如何训练大模型在复杂因素组成的系统中求得最优解
  • ¥15 关于#r语言#的问题:在进行倾向性评分匹配时,使用“match it"包提示”错误于eval(family$initialize): y值必需满足0 <= y <= 1“请问在进行PSM时
  • ¥45 求17位带符号原码乘法器verilog代码