Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 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 Guilherme
  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.  *
  20.  * @author Guilherme
  21.  */
  22. class Ponto{
  23.     double x,y;
  24.     public Ponto(double x, double y){
  25.         this.x = x;
  26.         this.y = y;
  27.     }
  28.    
  29.     public double getX(){
  30.         return x;
  31.     }
  32.     public double getY(){
  33.         return y;
  34.     }
  35.    
  36. }
  37. abstract class  Palindromo{
  38.     Ponto p1;
  39.     Ponto p2;
  40.    
  41.     public Palindromo(double x1, double y1, double x2, double y2){
  42.         p1 = new Ponto(x1,y1);
  43.         p2 = new Ponto(x2,y2);
  44.     }
  45.    
  46.     abstract double area();
  47. }
  48.  
  49. class Quadrado extends Palindromo
  50. {
  51.     public Quadrado(double x, double y, double lado){
  52.         super(x,y, x + lado, y - lado);
  53.     }
  54.    
  55.     @Override
  56.     double area() {
  57.         return Math.pow(p2.getX() - p1.getX(), 2);
  58.     }
  59.    
  60. }
  61. class Retangulo extends Palindromo{
  62.     public Retangulo(double x1, double y1, double x2, double y2){
  63.         super(x1,y1,x2,y2);
  64.     }
  65.  
  66.     @Override
  67.     double area() {
  68.         double lado1 = Math.abs(p2.getX() - p1.getX());
  69.         double lado2 = Math.abs(p1.getY() - p2.getY());
  70.        
  71.         return lado1 * lado2;
  72.     }
  73. }
  74.  
  75.  
  76. public class Main {
  77.  
  78.     /**
  79.      * @param args the command line arguments
  80.      */
  81.     public static void main(String[] args) {
  82.         Quadrado q = new Quadrado(5, 3, 2);
  83.         System.out.println(q.area());
  84.         System.out.println(q.p2.getX());
  85.         System.out.println(q.p2.getY());
  86.        
  87.         Retangulo r = new Retangulo(5, 5, 10, 0);
  88.         System.out.println(r.area());
  89.     }
  90.    
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement