This code is from kevinpadin21 and devsirji. They are helping me with my EllipsoidList.Java. They asked me for my Ellipsoid.Java. Please see below.
import java.text.DecimalFormat;
/**
*
*
* @author Ronald Funes
* @version Ellipsoid.Java
*/
public class Ellipsoid
{
//Fields
private String label = “”;
private double a = 0;
private double b = 0;
private double c = 0;
//constructor
/**
* @param labelIn establish the label
* @param aIn establishes a axes.
* @param bIn establishes b axes.
* @param cIn establishes c axes.
*/
public Ellipsoid(String labelIn, double aIn, double bIn, double cIn)
{
setLabel(labelIn);
setA(aIn);
setB(bIn);
setC(cIn);
}
//Methods
/**
* @return getLabel
*/
public String getLabel()
{
return label;
}
/**
*
* @param labelIn this retrieves a label.
* @return setLabel
*/
public boolean setLabel(String labelIn)
{
if (labelIn == null)
{
return false;
} else
{
label = labelIn.trim();
return true;
}
}
/**
*
* @return getA
*/
public double getA()
{
return a;
}
/**
*
* @param aIn this returms a boolean.
* @return setA
*/
public boolean setA(double aIn)
{
if (aIn > 0)
{
a = aIn;
return true;
} else
{
return false;
}
}
/**
*
* @return getB
*/
public double getB()
{
return b;
}
/**
*
* @param bIn this returms a boolean.
* @return setB
*/
public boolean setB(double bIn)
{
if (bIn > 0)
{
b = bIn;
return true;
} else
{
return false;
}
}
/**
*
* @return getC
*/
public double getC()
{
return c;
}
/**
*
* @param cIn this returna a boolean.
* @return setC
*/
public boolean setC(double cIn)
{
if (cIn > 0)
{
c = cIn;
return true;
} else
{
return false;
}
}
/**
*
* @return volume
*/
public double volume()
{
double volume = ((4 * Math.PI * a * b * c) / 3);
return volume;
}
/**
*
* @return surfaceArea
*/
public double surfaceArea()
{
double thePowers = (Math.pow((a * b), 1.6) + Math.pow((a * c), 1.6) + Math.pow((b * c), 1.6)) / 3;
double surfaceArea = 4 * Math.PI * Math.pow(thePowers, (1.0 / 1.6));
return surfaceArea;
}
/**
*
* @return toString
*/
public String toString()
{
DecimalFormat decimalFormat = new DecimalFormat(“#,##0.0###”);
return “Ellipsoid \”” + getLabel() + “\” with axes a = ” + decimalFormat.format(a) + “, b = ”
+ decimalFormat.format(b) + “, c = ” + decimalFormat.format(c) + ” units has:\n\tvolume = ”
+ decimalFormat.format(volume()) + ” cubic units” + “\n\tsurface area = ”
+ decimalFormat.format(surfaceArea()) + ” square units”;
}
public static void main(String[] args)
{
Ellipsoid example1 = new Ellipsoid (“Example1”, 2, 2, 2);
System.out.println(example1);
}
}