Created
April 12, 2017 08:50
-
-
Save meisheep/8d71d2f2ef79d56c298c68b9fcf889df to your computer and use it in GitHub Desktop.
Liu's homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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