Skip to content

Instantly share code, notes, and snippets.

@meisheep
Created April 12, 2017 08:50
Show Gist options
  • Save meisheep/8d71d2f2ef79d56c298c68b9fcf889df to your computer and use it in GitHub Desktop.
Save meisheep/8d71d2f2ef79d56c298c68b9fcf889df to your computer and use it in GitHub Desktop.
Liu's homework
abstract interface iVolume
{
public void showData();
public double vol();
}
abstract class CSphere implements iVolume
{
final double PI = 3.14;
protected int x;
protected int y;
protected int r;
public double vol() {
double volume = 4.0/3 * this.PI* Math.pow(this.r, 3);
return volume;
}
public void showData() {
System.out.println("center: (" + this.x + ", " + this.y + ')');
System.out.println("radius: " + this.r);
System.out.println("volume: " + vol());
}
}
class CCircle extends CSphere
{
public CCircle(int x, int y , int r) {
this.x = x;
this.y = y;
this.r = r;
}
}
public class HelloWorld
{
public static void main( String args[])
{
CCircle cir= new CCircle(8,6,2);
cir.showData();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment