Advertisement
azg2017

Untitled

Jun 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. package geometrics;
  2.  
  3. public interface Shape {
  4. public double getPerimeter();
  5.  
  6. }
  7.  
  8. public class Circle implements Shape{
  9. public double pi=3.14;
  10. public double getPerimeter(){
  11. return 2*pi;
  12. }
  13. }
  14.  
  15. public class Square implements Shape {
  16. public double side=5.00;
  17. @Override
  18. public double getPerimeter(){
  19. return 4*side;
  20. }
  21. }
  22.  
  23. public class Test {
  24. public static void main(){
  25. Circle c = new Circle();
  26. Square s= new Square();
  27.  
  28. Shape v[] = {c,s};
  29.  
  30. int sum=0;
  31. for (int i=0;i<v.length;i++){
  32. sum+=v[i].getPerimeter();
  33. }
  34. System.out.println(sum);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement