Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Solução para a pegadinha "Ponto2d" dos professores
- * IPCA: São 2 arquivos
- */
- // Ponto2d.java
- public class Ponto2d {
- private int x;
- private int y;
- public Ponto2d(int a, int b) { // Construtor Ponto2d
- this.setX(a);
- this.setY(b);
- }
- public double distancia(Ponto2d p) { // método distancia
- // double distX = p.x - x;
- // double distY = p.y - y;
- double distX = p.x;
- double distY = p.y;
- return Math.sqrt(distX*distX + distY*distY);
- }
- public int getX(){
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY(){
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- }
- // ImplP2d.java
- public class ImplP2d {
- public static void main(String[] args) {
- Ponto2d p = new Ponto2d(9, 7);
- System.out.println(p.getX());
- System.out.println(p.getY());
- System.out.println(p.distancia(p));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement