Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. public interface Shape
  2. {
  3.     public abstract double area();
  4. }
  5.  
  6. public class Circle implements Shape
  7. {
  8.     private double radius;
  9.    
  10.     public Circle(double radius)
  11.     {
  12.         this.radius = radius;
  13.     }
  14.    
  15.     public void setRadius(double radius)
  16.     {
  17.         this.radius = radius;
  18.     }
  19.    
  20.     public double getRadius()
  21.     {
  22.         return radius;
  23.     }
  24.    
  25.     public double area(double radius)
  26.     {
  27.         return getRadius()*getRadius()*3.14;
  28.     }
  29.    
  30. }
  31.  
  32. public class Rectangle implements Shape
  33. {
  34.     private double length;
  35.     private double width;
  36.    
  37.     public void setLength(double length)
  38.     {
  39.         this.length = length;
  40.     }
  41.    
  42.     public void setWidth(double width)
  43.     {
  44.         this.width = width;
  45.     }
  46.    
  47.     public double getLength()
  48.     {
  49.         return length;
  50.     }
  51.    
  52.     public double getWidth()
  53.     {
  54.         return width;
  55.     }
  56.    
  57.     public double area()
  58.     {
  59.         return getLength()*getWidth();
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement