Шукаєте відповіді та рішення тестів для ANÁLISIS Y DISEÑO DE SOFTWARE 2024/25? Перегляньте нашу велику колекцію перевірених відповідей для ANÁLISIS Y DISEÑO DE SOFTWARE 2024/25 в moodle.uam.es.
Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!
Considerar la siguiente implementación de un grafo ponderado (con pesos en sus arcos/edges) de vértices con datos genéricos (asumiendo todos los necesarios, así como los métodos hashCode, equals, compareTo y toString de la clase de un vértice: Vertex).
public class Vertex<T> implements Comparable<Vertex<T>> {
private final int id;
private T data;
public Vertex(int id, T data) {
this.id = id;
this.data = data;
}
public int getId() { return this.id; }
public T getData() { return this.data; }
...
}
public class Graph<T> {
protected List<Vertex<T>> vertices; // vértices v
protected Map<Vertex<T>, Map<Vertex<T>, Double>> edges; // arcos (v1,v2) con pesos w
public Graph() {
this.vertices = new ArrayList<>();
this.edges = new HashMap<>();
}
public Vertex<T> addVertex(T data) { ... }
public void addEdge(Vertex<T> v1, Vertex<T> v2,
public List<Vertex<T>> getVertices() { ... }
public double getEdgeWeight(Vertex<T> v1, Vertex<T> v2) { ... }
...
}
¿Qué es lo que almacena la variable x de abajo dentro de un método de Graph?
x = this.edges.get(v).entrySet()
.stream()
.filter(e -> e.getValue() > 0.5)
.map(e -> e.getKey())
.collect(Collectors.toList());
Tu equipo está desarrollando un . Se plantea una clase para la creación de criaturas de diferentes tipos, y la inicialización de éstas con unos atributos físicos y de comportamiento dados. Asumiendo clases (abstracta), un compañero te propone la siguiente implementación:
public class CreatureCreator {
public Creature newCreature(CreatureType type,
PhysicalAttributes physicalAttributes,
BehavioralAttributes behavioralAttributes) {
Creature creature = null;
if (type.equals(CreatureType.
creature = new Goblin();
} else if (type.equals(CreatureType.
creature = new Ogre();
} else if (type.equals(CreatureType.
creature = new Orc();
} else if (type.equals(CreatureType.TROLL)) {
creature = new Troll();
}
creature.setPhysicalAttributes(physicalAttributes);
creature.setBehavioralAttributes(behavioralAttributes);
return creature;
} // newCreature
}
Claramente ves inconvenientes (¿cuáles?) en la implementación, y le propones seguir el patrón . Te entrega el siguiente código:
public abstract class CreatureCreator {
public Creature newCreature(CreatureType type,
PhysicalAttributes physicalAttributes,
BehavioralAttributes behavioralAttributes) {
Creature creature = null;
creature = this.createCreature(type);
creature.setPhysicalAttributes(physicalAttributes);
creature.setBehavioralAttributes(behavioralAttributes);
return creature;
} // newCreature
public abstract Creature createCreature(CreatureType type);
}
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) {
@Override public String toString() {
}
public class Employee extends Person {
public Employee(String name) {
@Override public String toString() {
}
public class Manager extends Employee {
public Manager(String name) {
@Override public String toString() {
}
. . .
// En la clase PersonTest
@SuppressWarnings("unchecked")
public static ______ P get(______ list, int pos) {
return (P) list.get(pos);
}
¿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() {
}
public class Edge<T, V extends Vertex<T>> {
public V v1;
public V v2;
public Edge(___[1]___) {
public String toString() {
}
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() {
}
¿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]___ ;
}
}
¿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);
}
}
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());
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()); //1Set<Object> myset1 = new MyHashSet<Integer>(new FilterOdd()); //2Set<Integer> myset3 = new MyHashSet<Integer>(new FilterNull()); //3
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); }}
Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!