简体   繁体   中英

Can't figure out why i keep getting cannot find symbol compile error

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;
  }
}
}

I keep getting a cannot find symbol compile time error on getArea, getVolume, getHeight, and getDiameter. I'm just a beginner so any help would be appreciated. I'm using this with another file but I can't figure out the problem

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.");


 }
 }

This is Cylinder.

The Code for the Cylinder class type must be available to the compiler because CylinderList class is referencing it. Compiler is not able to find it in the java file being compiled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM