Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package coinhunt;
- /**
- *
- * @author Jessica
- */
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- class Ponto{
- double x,y;
- public Ponto(double x, double y){
- this.x = x;
- this.y = y;
- }
- public double getX(){
- return x;
- }
- public double getY(){
- return y;
- }
- }
- abstract class Palindromo{
- Ponto p1;
- Ponto p2;
- public Palindromo(double x1, double y1, double x2, double y2){
- p1 = new Ponto(x1,y1);
- p2 = new Ponto(x2,y2);
- }
- abstract double area();
- }
- class Quadrado extends Palindromo
- {
- public Quadrado(double x, double y, double lado){
- super(x,y, x + lado, y - lado);
- }
- @Override
- double area() {
- return Math.pow(p2.getX() - p1.getX(), 2);
- }
- }
- class Retangulo extends Palindromo{
- public Retangulo(double x1, double y1, double x2, double y2){
- super(x1,y1,x2,y2);
- }
- @Override
- double area() {
- double lado1 = Math.abs(p2.getX() - p1.getX());
- double lado2 = Math.abs(p1.getY() - p2.getY());
- return lado1 * lado2;
- }
- }
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Quadrado q = new Quadrado(5, 3, 2);
- System.out.println(q.area());
- System.out.println(q.p2.getX());
- System.out.println(q.p2.getY());
- Retangulo r = new Retangulo(5, 5, 10, 0);
- System.out.println(r.area());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement