logo

Crowdly

ANÁLISIS Y DISEÑO DE SOFTWARE 2024/25

Looking for ANÁLISIS Y DISEÑO DE SOFTWARE 2024/25 test answers and solutions? Browse our comprehensive collection of verified answers for ANÁLISIS Y DISEÑO DE SOFTWARE 2024/25 at moodle.uam.es.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

Dadas las clases de abajo,

¿cómo de declararía un método get que devuelva el elemento en la posición pos

de una lista con objetos de alguna de esas clases?

public class Person {

  protected String name;

  public

Person(String

name) {

this.name = name; }

  @Override public

String

toString() {

return "Person: " + this.name; }

}

public class Employee extends Person {

  public

Employee(String

name) {

super(name); }

  @Override public

String

toString() {

return "Employee: " + this.name; }

}

public class Manager extends Employee {

  public

Manager(String

name) {

super(name); }

  @Override public

String

toString() {

return "Manager: " + this.name; }

}

. . .

// En la clase PersonTest

@SuppressWarnings("unchecked")

public static

______ P get(______ list, int pos)

{

  return (P) list.get(pos);

}

0%
0%
0%
View this question

¿Qué código hay que poner en

___[1]___ para implementar el constructor de la clase Edge (sin considerar el

control de argumentos de entrada)

public class Vertex<T> {

  private long id;

  private T data;

  public Vertex(long id, T data) { this.id = id; this.data = data; }

  public T getData() { return this.data; }

  public

String

toString() {

return "v" + this.id + "=" + this.data; } 

}

public class Edge<T, V extends Vertex<T>> {

  public V v1;

  public V v2;

  public

Edge(___[1]___)

{

this.v1 = v1; this.v2 = v2; }

  public

String toString()

{

return "[" + this.v1 + "," + this.v2 + "]"; }

}

View this question

Considerando la clase Vertex

(vértice de un grafo) dada abajo, ¿cómo definirías una clase llamada Edge

(arco), que contenga los dos vértices que conecta?

public class Vertex<T> {

  private long id;

  private T data; 

  public Vertex(long id, T data) { this.id = id; this.data = data; }

  public T getData() { return this.data; }

  public

String

toString() {

return "v" + this.id + "=" + this.data; } 

}

View this question

¿Qué código hay que poner en

___[1]___ para implementar el método equals() de la clase Point (sin considerar

el control de argumentos de entrada)

public class Point<T> {

  private T x, y;  

  public

Point (T x, T

y) {

     this.x = x;

     this.y = y;

  }

  @Override

  public boolean

equals(Object

obj) {

     return ___[1]___ ;

  }

}

0%
100%
0%
0%
View this question

¿Cuál de las opciones de

abajo es correcta atendiendo al siguiente código?

public class Point<T extends Float> {

  private T x, y;

  public

Point (T x, T

y) {

     this.x = x;

     this.y = y;

  }

  public

String

toString() {

     return this.x + " " + this.y;

  }

  public static void

main(String[]

args) {

    Point<Double> p = new Point<Double>(2.0, -3.5);

     System.out.println(p);

  }

}

0%
0%
0%
View this question

Dado el siguiente código

interface IFilter<T> { public boolean check(T ele); }

class FilterNull implements IFilter<Object> {

    public boolean check(Object ele) {    return ele!=null; }   

}

public class MyHashSet<T> extends HashSet<T>{

    private IFilter<___[1]___> filter;

    public MyHashSet (IFilter<___[2]___> filter) {

        this.filter = filter;

    }

}

¿Qué código hay que poner en los huecos [1] y [2] para permitir la siguiente declaración?

Set<Integer> myset3 = new MyHashSet<Integer>(new FilterNull());

View this question

Queremos crear un tipo de conjunto que filtre sus elementos de acuerdo con un criterio configurable. Para ello, creamos las siguientes interfaces y clases genéricas

interface IFilter<T> { public boolean check(T ele); }

class FilterNull implements IFilter<Object> {

    public boolean check(Object ele) {    return ele!=null; }   

}

class FilterOdd implements IFilter<Integer> {

    public boolean check(Integer ele) {    return ele%2==0; }   

}

public class MyHashSet<T> extends HashSet<T>{

    private IFilter<T> filter;

    public MyHashSet (IFilter<T> filter) { this.filter = filter; }

   

    @Override public boolean add (T e) {

        if (!this.filter.check(e)) return false;

        return super.add(e);

    }

}

¿Cuál de las siguientes líneas de código son erróneas?

Set<Object>  myset0 = new MyHashSet<Object>(new FilterNull());    //1

Set<Object>  myset1 = new MyHashSet<Integer>(new FilterOdd());    //2

Set<Integer> myset3 = new MyHashSet<Integer>(new FilterNull());    //3

0%
0%
0%
View this question

Indica cual de las siguientes afirmaciones es verdadera sobre el siguiente código

class Punto<T> implements Comparable<Punto<T>>{

    private T x, y;

   

    public Punto (T x, T y) {

        this.x = x;

        this.y = y;

    }

    @Override public int compareTo(Punto<T> p) {

        if (this.x.compareTo(p.x) !=0 ) return this.x.compareTo(p.x);

        return this.y.compareTo(p.y);

    }

}

0%
0%
0%
View this question

¿Hay errores de compilación o ejecución en el siguiente código?

import java.util.*;

class Punto<T> {

    private T x, y;

   

    public Punto (T x, T y) {

        this.x = x;

        this.y = y;

    }

   

    public static void main(String[] args) {

        Set<Punto<Integer>> lp = new TreeSet<> (

                Arrays.asList(new Punto<Integer>(3, 3),

                              new Punto<Integer>(0, 0)));

    }

}

0%
0%
View this question

¿Hay errores en la siguiente clase genérica?

class Point<?> {

    private ? x, y;

   

    public Point (? x, ? y) {

        this.x = x;

        this.y = y;

    }

}

View this question

Want instant access to all verified answers on moodle.uam.es?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!