How to implement Abstract Data Type?

1

Good night, I need to do a TAD point implementation, I'm getting to do in Python, but the problem is that it should be implemented in Java and I have no idea how to get started.

import math
class Ponto(object):

  def __init__(self, x=0, y=0):
    self.x=x
    self.y=y

  def igual(self, ponto):
    return self.x == ponto.x and self.y == ponto.y

  def texto(self):
    return '('+str(self.x)+', '+str(self.y)+')'

  def distancia(self, ponto):
    d1=self.x-ponto.x
    d2=self.y-ponto.y
    return math.sqrt(d1*d1+d2*d2)

  def translada(self, dx, dy):
    self.x=self.x+dx
    self.y=self.y+dy
    
asked by anonymous 09.05.2018 / 05:32

1 answer

0
import java.lang.Math;
class Ponto(){

private int x;
private int y;


public Ponto(int x, int y){
    this.x = x;
    this.y = y;
}

public boolean igual(Ponto ponto){
    return this.x == ponto.x && this.y == ponto.y;
}

public String texto(){
    return (this.x + " " this.y);
}

public int distancia(Ponto ponto){
    int d1 = this.x - ponto.x;
    int d2 = this.y - ponto.y;
    return Math.sqrt((d1*d1)+(d2*d2));
}

public void translada(int dx, int dy){
    this.x = this.x+dx;
    thix.y = this.y+dy;
}

}

class chamaPonto{
       public static void main(String[] args) {
            Ponto ponto = new Ponto(5,10)
            Ponto ponto2 = new Ponto(10,5)
            ponto.igual(ponto2) //vai retornar false
            ponto.texto() //vai retornar "5 10"
            ponto.distancia(ponto2) //vai retornar a distância entre os pontos
            ponto.translada(5,10) //vai somar 5 ao x e 10 ao y
    }
}
    
09.05.2018 / 13:11