Advertisement
Guest User

interface

a guest
Nov 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1.  
  2. package shapecunt;
  3.  
  4. public class ShapeCunt {
  5.  
  6.     public static void main(String[] args) {
  7.        
  8.     }
  9.    
  10. }
  11. ---------------------------------
  12.  
  13. package shapecunt;
  14.  
  15. public interface Calculatable {
  16.     public static final double PI = 3.14;
  17.     public static double calcArea() {
  18.         return 0.0;
  19.     };
  20. }
  21. -----------------------------------
  22.  
  23. package shapecunt;
  24.  
  25. // area = 3.14*r2
  26. public class Circle implements Calculatable {
  27.     private double r;
  28.    
  29.     public Circle(double radius) {
  30.         this.r = radius;
  31.     }
  32.  
  33.     public double getR() {
  34.         return r;
  35.     }
  36.  
  37.     public void setR(double r) {
  38.         this.r = r;
  39.     }
  40.    
  41.     public double calcArea() {
  42.         return Calculatable.PI * getR();
  43.     }
  44.    
  45. }
  46. ------------------------------------
  47.  
  48. package shapecunt;
  49.  
  50. public class Triangle implements Calculatable {
  51.     private double height ;
  52.    private double base ;
  53.  
  54.     /**
  55.      * @return the height
  56.      */
  57.     public double getHeight() {
  58.         return height;
  59.     }
  60.  
  61.     /**
  62.      * @param height the height to set
  63.      */
  64.     public void setHeight(double height) {
  65.         this.height = height;
  66.     }
  67.  
  68.     /**
  69.      * @return the base
  70.      */
  71.     public double getBase() {
  72.         return base;
  73.     }
  74.  
  75.     /**
  76.      * @param base the base to set
  77.      */
  78.     public void setBase(double base) {
  79.         this.base = base;
  80.     }
  81.     public double calcArea () {
  82.    return getBase() * getHeight() * 0.5;
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement