public class CylinderList
{
private String listName = "";
private ArrayList<Cylinder> cyll =
new ArrayList<Cylinder>();
public CylinderList(String listNameIn,
ArrayList<Cylinder> cyllIn)
{
listName = listNameIn;
cyll = cyllIn;
}
public String getName()
{
return listName;
}
public int numberofCylinders()
{
return cyll.size();
}
public double totalArea()
{
double Area = 0;
int index = 0;
if (cyll.size() == 0)
{
return 0;
}
while (index < cyll.size())
{
Area += cyll.get(index).getArea();
index++;
}
return Area;
}
public double totalVolume()
{
double Volume = 0;
int index = 0;
if (cyll.size() == 0)
{
return 0;
}
while (index < cyll.size())
{
Volume += cyll.get(index).getVolume();
index++;
}
return Volume;
}
public double totalHeight()
{
double Height = 0;
int index = 0;
if (cyll.size() == 0)
{
return 0;
}
while (index < cyll.size())
{
Height += cyll.get(index).getHeight();
index++;
}
return Height;
}
public double totalDiameter()
{
double Diameter = 0;
int index = 0;
if (cyll.size() == 0)
{
return 0;
}
while (index < cyll.size())
{
Diameter += cyll.get(index).getDiameter();
index++;
}
return Diameter;
}
public double averageArea()
{
double aArea = 0;
int index = 0;
if (cyll.size() == 0)
{
return 0;
}
else
{
aArea += totalArea() / cyll.size();
return aArea;
}
}
public double averageVolume()
{
double aVolume = 0;
int index = 0;
if (cyll.size() == 0)
{
return 0;
}
else
{
aVolume += totalVolume() / cyll.size();
return aVolume;
}
}
}
我一直在getArea,getVolume,getHeight和getDiameter上找不到符号编译时错误。我只是一个初学者,所以任何帮助将不胜感激。我将其与另一个文件一起使用但我无法解决问题
import java.text.DecimalFormat;
public class Cylinder
{
// Fields
private String label = "";
private double radius;
private double height;
/**
*@param labelIn Command line arguements (not used).
*@param radiusIn Command line arguements (not used).
*@param heightIn Command line arguements (not used).
*/
public Cylinder(String labelIn, double radiusIn, double heightIn)
{
label = labelIn;
radius = radiusIn;
height = heightIn;
}
/**
*@return String representation of label.
*/
public String getlabel()
{
return label;
}
/**
*@param labelIn The formal parameter for the set label method.
*@return checks to see if labelIn exist.
*/
public boolean setlabel(String labelIn)
{
if (labelIn == null)
{
return false;
}
else
{
label = labelIn.trim();
return true;
}
}
/**
*@return a method to display a double radius.
*/
public double getRadius()
{
return radius;
}
/**
*@param radiusIn the formal parameter for the setRadius method.
*/
public void setRadius(double radiusIn)
{
radius = radiusIn;
}
/**
*@return a method to display a double height.
*/
public double getHeight()
{
return height;
}
/**
*@param heightIn the formal parameter for the setHeight method.
*/
public void setHeight(double heightIn)
{
height = heightIn;
}
/**
*@return displays diameter when method is called.
*/
public double diameter()
{
return radius * 2;
}
/**
*@return displays circumference when method is called.
*/
public double circumference()
{
return Math.PI * radius * 2;
}
/**
*@return displays area when method is called.
*/
public double area()
{
return 2 * Math.PI * radius * radius + 2 * Math.PI * radius * height;
}
/**
*@return displays volume when method is called.
*/
public double volume()
{
return Math.PI * radius * radius * height;
}
/**
*@return displays cylinder information.
*/
public String toString()
{
DecimalFormat fmt = new DecimalFormat("#,##0.0##");
return
("Enter label, radius, and height for a cylinder."
+ "\n\tlabel: " + label
+ "\n\tradius: " + fmt.format(getRadius())
+ "\n\theight: " + fmt.format(getHeight())
+ "\n\"" + label + "\" is a cylinder with radius = "
+ fmt.format(getRadius())
+ " units and height = " + fmt.format(getHeight()) + " units,"
+ "\nwhich has diameter = " + fmt.format(diameter())
+ " units, circumference = "
+ fmt.format(circumference()) + " units,"
+ "\narea = " + fmt.format(area()) + " square units,"
+ " and volume = " + fmt.format(volume()) + " cubic units.");
}
}
这是Cylinder。
答案 0 :(得分:0)
Cylinder类的代码必须可供编译器使用,因为CylinderList类正在引用它。编译器无法在正在编译的java文件中找到它。