a java program that will compute the surface area and volume of a cube using class
import java.util.Scanner;
//Implement class Cube
class Cube
{
private double a;
public Cube()//Default constructor
{
this.a=0.0;
}
public Cube(double _a)
{
this.a=_a;
}
//Calc volume a*a*a
public double Volume()
{
return a*a*a;
}
public double TotalSurfaceArea()
{
return 6*a*a;
}
public double CurveSurfaceArea()
{
return 4*a*a;
}
}
class Main {
public static void main(String[] args) {
System.out.print("Please enter inches each side(a): ");
Scanner cin=new Scanner(System.in);
double a=cin.nextDouble();
Cube cb=new Cube(a);
System.out.println("Total Surface Area: "+cb.TotalSurfaceArea());
System.out.println("Curve Surface Area: "+cb.CurveSurfaceArea());
System.out.println("Volume : "+cb.Volume());
}
}
Comments
Leave a comment