Advertisement
Aech5

Untitled

Nov 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package coinhunt;
  7.  
  8. /**
  9.  *
  10.  * @author Jessica
  11.  */
  12. /*
  13.  * To change this license header, choose License Headers in Project Properties.
  14.  * To change this template file, choose Tools | Templates
  15.  * and open the template in the editor.
  16.  */
  17.  
  18.  
  19. class Ponto{
  20.     double x,y;
  21.     public Ponto(double x, double y){
  22.         this.x = x;
  23.         this.y = y;
  24.     }
  25.    
  26.     public double getX(){
  27.         return x;
  28.     }
  29.     public double getY(){
  30.         return y;
  31.     }
  32.    
  33. }
  34. abstract class  Palindromo{
  35.     Ponto p1;
  36.     Ponto p2;
  37.    
  38.     public Palindromo(double x1, double y1, double x2, double y2){
  39.         p1 = new Ponto(x1,y1);
  40.         p2 = new Ponto(x2,y2);
  41.     }
  42.    
  43.     abstract double area();
  44. }
  45.  
  46. class Quadrado extends Palindromo
  47. {
  48.     public Quadrado(double x, double y, double lado){
  49.         super(x,y, x + lado, y - lado);
  50.     }
  51.    
  52.     @Override
  53.     double area() {
  54.         return Math.pow(p2.getX() - p1.getX(), 2);
  55.     }
  56.    
  57. }
  58. class Retangulo extends Palindromo{
  59.     public Retangulo(double x1, double y1, double x2, double y2){
  60.         super(x1,y1,x2,y2);
  61.     }
  62.  
  63.     @Override
  64.     double area() {
  65.         double lado1 = Math.abs(p2.getX() - p1.getX());
  66.         double lado2 = Math.abs(p1.getY() - p2.getY());
  67.        
  68.         return lado1 * lado2;
  69.     }
  70. }
  71.  
  72.  
  73. public class Main {
  74.  
  75.     /**
  76.      * @param args the command line arguments
  77.      */
  78.     public static void main(String[] args) {
  79.         Quadrado q = new Quadrado(5, 3, 2);
  80.         System.out.println(q.area());
  81.         System.out.println(q.p2.getX());
  82.         System.out.println(q.p2.getY());
  83.        
  84.         Retangulo r = new Retangulo(5, 5, 10, 0);
  85.         System.out.println(r.area());
  86.     }
  87.    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement