2015-10-05 77 views
-2
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."); 


} 
} 

這是缸。

+3

請張貼'Cylinder'。 –

+0

你從哪裏得到這個錯誤?而在Cylinder中使用這個類的方法? – yogidilip

+0

並使用正確的格式。除了上面的評論之外,你還會在結尾丟失一個右括號。 – Jags

回答

0

Cylinder類類型的代碼必須可供編譯器使用,因爲CylinderList類正在引用它。編譯器無法在正在編譯的java文件中找到它。

相關問題