3

ユーザーから円柱の半径と高さの入力を取得し、ボリュームを返すという宿題があります。ほとんどの作業は完了したと思いますが、すべてをまとめるのに苦労しています。すべてを印刷しようとすると、構文エラーが発生します。プリントラインはこちら

for (int i = 0; i < volume.length; i++)
{
    System.out.println("for Radius of:" + volume[i].getRadius() + " and Height of:" + volume[i].getHeight() + " the Volume is:" + volume.getVolume());
}

メインクラスはこちら

import javax.swing.*;

//Driver class
public class CylinderTest
{

    public static void main(String[] args)
    {

        Cylinder[] volume = new Cylinder[3];
        for (int counter = 0; counter < volume.length; counter++)
        {
            double radius = Double.parseDouble(JOptionPane
                    .showInputDialog("Enter the radius"));
            double height = Double.parseDouble(JOptionPane
                    .showInputDialog("Enter the height"));
            volume[counter] = new Cylinder(radius, height);
        }

        for (int i = 0; i < volume.length; i++)
        {
            System.out.println("for Radius of:" + volume[i].getRadius() + " and Height of:" + volume[i].getHeight() + " the Volume is:" + volume.getVolume());
        }
    }
}

ここに Cylinder クラスがあります

public class Cylinder
{
    // variables
    public static final double PI = 3.14159;
    private double radius, height, volume;

    // constructor
    public Cylinder(double radius, double height)
    {
        this.radius = radius;
        this.height = height;
        this.volume = volume;
    }

    // default constructor
    public Cylinder()
    {this(0, 0);}

    // accessors and mutators (getters and setters)
    public double getRadius()
    {return radius;}

    private void setRadius(double radius)
    {this.radius = radius;}

    public double getHeight()
    {return height;}

    private void setHeight(double height)
    {this.height = height;}

    public double getVolume()
    {return volume;}

    // Volume method to compute the volume of the cylinder
    public double volume()
    {return PI * radius * radius * height;}

    public String toString()
    {return volume + "\t" + radius + "\t" + height; }

}

Cylinder クラスの getVolume ゲッターからボリュームを取得しようとしています。

4

3 に答える 3