Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package shapecunt;
- public class ShapeCunt {
- public static void main(String[] args) {
- }
- }
- ---------------------------------
- package shapecunt;
- public interface Calculatable {
- public static final double PI = 3.14;
- public static double calcArea() {
- return 0.0;
- };
- }
- -----------------------------------
- package shapecunt;
- // area = 3.14*r2
- public class Circle implements Calculatable {
- private double r;
- public Circle(double radius) {
- this.r = radius;
- }
- public double getR() {
- return r;
- }
- public void setR(double r) {
- this.r = r;
- }
- public double calcArea() {
- return Calculatable.PI * getR();
- }
- }
- ------------------------------------
- package shapecunt;
- public class Triangle implements Calculatable {
- private double height ;
- private double base ;
- /**
- * @return the height
- */
- public double getHeight() {
- return height;
- }
- /**
- * @param height the height to set
- */
- public void setHeight(double height) {
- this.height = height;
- }
- /**
- * @return the base
- */
- public double getBase() {
- return base;
- }
- /**
- * @param base the base to set
- */
- public void setBase(double base) {
- this.base = base;
- }
- public double calcArea () {
- return getBase() * getHeight() * 0.5;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement