Examen 2025/02/21
This commit is contained in:
44
.idea/workspace.xml
generated
44
.idea/workspace.xml
generated
@@ -4,19 +4,20 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e2c4f742-461e-4c7a-a6e0-b5f4b8e8f229" name="Changes" comment="Examen 2024/12/13">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio01/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio02/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio02/Persona.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio02/exceptions/EdadInvalidaException.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio03/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04/Matematico.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04/listener/CheckeadorNums.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04/listener/NumNegativoEvent.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04/listener/NumeroNegativoListener.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250131/utils/Utils.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<list default="true" id="e2c4f742-461e-4c7a-a6e0-b5f4b8e8f229" name="Changes" comment="Examen 2025/01/31">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio01/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio01/Producto.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio02/Letra.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio02/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio03/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio03/Prestamo.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/Main.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/Matematico.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/NumeroMenor100Exception.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/listener/CheckeadorNums.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/listener/NumRepetidoEvent.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/listener/NumsListener.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/utils/Utils.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@@ -60,7 +61,7 @@
|
||||
"dart.analysis.tool.window.visible": "false",
|
||||
"git-widget-placeholder": "main",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/examenes/examen20250131/ejercicio04",
|
||||
"last_opened_file_path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/examenes/examen20250221/ejercicio04",
|
||||
"onboarding.tips.debug.path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/net/h4ckx0r/Main.java",
|
||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||
"show.migrate.to.gradle.popup": "false"
|
||||
@@ -68,9 +69,11 @@
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04" />
|
||||
<recent name="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04" />
|
||||
</key>
|
||||
<key name="CopyClassDialog.RECENTS_KEY">
|
||||
<recent name="examenes.examen20250221.ejercicio04" />
|
||||
<recent name="examenes.examen20241213" />
|
||||
<recent name="examenes.examen20241122" />
|
||||
<recent name="examenes.examen20241025" />
|
||||
@@ -181,7 +184,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1734091528594</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="13" />
|
||||
<task id="LOCAL-00013" summary="Examen 2025/01/31">
|
||||
<option name="closed" value="true" />
|
||||
<created>1738328024100</created>
|
||||
<option name="number" value="00013" />
|
||||
<option name="presentableId" value="LOCAL-00013" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1738328024100</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="14" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
@@ -208,6 +219,7 @@
|
||||
<MESSAGE value="Se formatea utils" />
|
||||
<MESSAGE value="Examen 2024/11/21" />
|
||||
<MESSAGE value="Examen 2024/12/13" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Examen 2024/12/13" />
|
||||
<MESSAGE value="Examen 2025/01/31" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Examen 2025/01/31" />
|
||||
</component>
|
||||
</project>
|
||||
63
src/main/java/examenes/examen20250221/ejercicio01/Main.java
Normal file
63
src/main/java/examenes/examen20250221/ejercicio01/Main.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package examenes.examen20250221.ejercicio01;
|
||||
|
||||
import examenes.examen20250221.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
HashMap<String, Producto> productos = new HashMap<>();
|
||||
int opcion;
|
||||
|
||||
productos.put("Cocacola", new Producto(1,"Cocacola", 1));
|
||||
productos.put("Pepsi", new Producto(1,"Pepsi", 1.2));
|
||||
productos.put("Galletas", new Producto(1,"Galletas", 0.8));
|
||||
productos.put("Chicles", new Producto(1,"Chicles", 0.25));
|
||||
|
||||
do {
|
||||
System.out.println("Seleccione lo que desea hacer:\n" +
|
||||
"0. Salir\n" +
|
||||
"1. Introducir productos\n" +
|
||||
"2. Mostrar producto más barato\n" +
|
||||
"3. Mostrar productos ordenados de más caro a más barato");
|
||||
|
||||
opcion = Utils.solicitarIntScannerInline("> ");
|
||||
switch (opcion) {
|
||||
case 1:
|
||||
Producto productoNuevo = new Producto(
|
||||
Utils.solicitarIntScannerInline("Introduzca el código del producto: "),
|
||||
Utils.solicitarStringScannerInline("Introduzca el nombre del producto: "),
|
||||
Utils.solicitarDoubleScannerInline("Introduzca el precio del producto: ")
|
||||
);
|
||||
productos.put(productoNuevo.getNombre(), productoNuevo);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
List<Producto> listaProductosPrimerItem = new ArrayList<>();
|
||||
for (Object producto : productos.values().toArray()) {
|
||||
listaProductosPrimerItem.add((Producto) producto);
|
||||
}
|
||||
listaProductosPrimerItem = Utils.ordenarBurbujaProductosPorPrecio(listaProductosPrimerItem);
|
||||
|
||||
System.out.println(listaProductosPrimerItem.getLast());
|
||||
break;
|
||||
case 3:
|
||||
List<Producto> listaProductos = new ArrayList<>();
|
||||
for (Object producto : productos.values().toArray()) {
|
||||
listaProductos.add((Producto) producto);
|
||||
}
|
||||
listaProductos = Utils.ordenarBurbujaProductosPorPrecio(listaProductos);
|
||||
|
||||
for (Producto p : listaProductos) {
|
||||
System.out.println(p.toString());
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
} while (opcion != 0);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package examenes.examen20250221.ejercicio01;
|
||||
|
||||
public class Producto {
|
||||
private int codigo;
|
||||
private String nombre;
|
||||
private double precio;
|
||||
|
||||
public Producto(int codigo, String nombre, double precio) {
|
||||
this.codigo = codigo;
|
||||
this.nombre = nombre;
|
||||
this.precio = precio;
|
||||
}
|
||||
|
||||
public int getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
public void setCodigo(int codigo) {
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public double getPrecio() {
|
||||
return precio;
|
||||
}
|
||||
|
||||
public void setPrecio(double precio) {
|
||||
this.precio = precio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Producto{" +
|
||||
"codigo=" + codigo +
|
||||
", nombre='" + nombre + '\'' +
|
||||
", precio=" + precio +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
31
src/main/java/examenes/examen20250221/ejercicio02/Letra.java
Normal file
31
src/main/java/examenes/examen20250221/ejercicio02/Letra.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package examenes.examen20250221.ejercicio02;
|
||||
|
||||
public class Letra {
|
||||
private Character letra;
|
||||
private Integer conteoLetra;
|
||||
|
||||
public Letra(Character letra, Integer conteoLetra) {
|
||||
this.letra = letra;
|
||||
this.conteoLetra = conteoLetra;
|
||||
}
|
||||
|
||||
public Integer getConteoLetra() {
|
||||
return conteoLetra;
|
||||
}
|
||||
|
||||
public void setConteoLetra(Integer conteoLetra) {
|
||||
this.conteoLetra = conteoLetra;
|
||||
}
|
||||
|
||||
public void sumaConteo() {
|
||||
this.conteoLetra++;
|
||||
}
|
||||
|
||||
public Character getLetra() {
|
||||
return letra;
|
||||
}
|
||||
|
||||
public void setLetra(Character letra) {
|
||||
this.letra = letra;
|
||||
}
|
||||
}
|
||||
55
src/main/java/examenes/examen20250221/ejercicio02/Main.java
Normal file
55
src/main/java/examenes/examen20250221/ejercicio02/Main.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package examenes.examen20250221.ejercicio02;
|
||||
|
||||
import examenes.examen20250221.ejercicio01.Producto;
|
||||
import examenes.examen20250221.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
String linea = Utils.solicitarStringScannerInline("Introduzca la línea a analizar: ").toLowerCase();
|
||||
|
||||
HashMap<Character, Letra> letras = new HashMap<>();
|
||||
int numDigitos = 0;
|
||||
int numEspacios = 0;
|
||||
int numOtros = 0;
|
||||
int numLetras = 0;
|
||||
|
||||
for (Character c : linea.toCharArray()) {
|
||||
if (Character.isLetter(c)) {
|
||||
Letra conteoLetra = letras.get(c);
|
||||
if (conteoLetra == null) {
|
||||
letras.put(c, new Letra(c, 1));
|
||||
} else {
|
||||
letras.get(c).sumaConteo();
|
||||
}
|
||||
numLetras++;
|
||||
} else if (Character.isDigit(c)) {
|
||||
numDigitos++;
|
||||
} else if (Character.isSpaceChar(c)) {
|
||||
numEspacios++;
|
||||
} else {
|
||||
numOtros++;
|
||||
}
|
||||
}
|
||||
|
||||
List<Letra> listaLetras = new ArrayList<>();
|
||||
for (Object producto : letras.values().toArray()) {
|
||||
listaLetras.add((Letra) producto);
|
||||
}
|
||||
|
||||
listaLetras = Utils.ordenarBurbujaLetras(listaLetras);
|
||||
|
||||
|
||||
System.out.println("La línea de texto tiene " + numLetras + " letras.");
|
||||
System.out.println("La línea de texto tiene " + numDigitos + " digitos.");
|
||||
System.out.println("La línea de texto tiene " + numEspacios + " espacios.");
|
||||
System.out.println("La línea de texto tiene " + numOtros + " otros caracteres.");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
System.out.println("La " + (i + 1) + "ª letra más frecuente es la: " + listaLetras.get(i).getLetra());
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/main/java/examenes/examen20250221/ejercicio03/Main.java
Normal file
36
src/main/java/examenes/examen20250221/ejercicio03/Main.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package examenes.examen20250221.ejercicio03;
|
||||
|
||||
import examenes.examen20250221.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
List<Prestamo> prestamos = new ArrayList<>();
|
||||
int opcion;
|
||||
|
||||
do {
|
||||
System.out.println("Seleccione lo que desea hacer:\n" +
|
||||
"0. Salir\n" +
|
||||
"1. Coger prestado un libro");
|
||||
|
||||
opcion = Utils.solicitarIntScannerInline("> ");
|
||||
switch (opcion) {
|
||||
case 1:
|
||||
Prestamo nuevoPrestamo = new Prestamo(
|
||||
Utils.solicitarFechaInline("dd/MM/yyyy"),
|
||||
Utils.solicitarIntScannerInline("Introduzca el código de usuario: "),
|
||||
Utils.solicitarIntScannerInline("Introduzca el ISBN del libro: "),
|
||||
Utils.solicitarIntScannerInline("Escriba 1 si es un libro de alta demanda o 0 si es demanda normal: ") == 1);
|
||||
|
||||
prestamos.add(nuevoPrestamo);
|
||||
System.out.println("\n\nTendrás que devolver el libro el " + nuevoPrestamo.getFechaEntrega());
|
||||
break;
|
||||
|
||||
}
|
||||
} while (opcion != 0);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package examenes.examen20250221.ejercicio03;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class Prestamo {
|
||||
private static final int DIAS_LIBRO_NORMAL = 15;
|
||||
private static final int DIAS_LIBRO_ALTA_DEMANDA = 7;
|
||||
|
||||
private Date fechaComienzo;
|
||||
private Date fechaEntrega;
|
||||
|
||||
private int codUser;
|
||||
private int isbnLibro;
|
||||
|
||||
private boolean altaDemanda;
|
||||
|
||||
public Prestamo(Date fechaComienzo, int codUser, int isbnLibro, boolean altaDemanda) {
|
||||
this.fechaComienzo = fechaComienzo;
|
||||
this.codUser = codUser;
|
||||
this.isbnLibro = isbnLibro;
|
||||
this.altaDemanda = altaDemanda;
|
||||
|
||||
long fechaEntrega;
|
||||
|
||||
if (altaDemanda) {
|
||||
fechaEntrega = fechaComienzo.getTime() + (DIAS_LIBRO_ALTA_DEMANDA * 24 * 60 * 60 * 1000);
|
||||
} else {
|
||||
fechaEntrega = fechaComienzo.getTime() + (DIAS_LIBRO_NORMAL * 24 * 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
Calendar calendarEntrega = Calendar.getInstance();
|
||||
calendarEntrega.setTimeInMillis(fechaEntrega);
|
||||
|
||||
if (calendarEntrega.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
|
||||
fechaEntrega += (24 * 60 * 60 * 1000);
|
||||
} else if (calendarEntrega.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
|
||||
fechaEntrega += (2 * 24 * 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
this.fechaEntrega = new Date(fechaEntrega);
|
||||
|
||||
}
|
||||
|
||||
public Date getFechaComienzo() {
|
||||
return fechaComienzo;
|
||||
}
|
||||
|
||||
public void setFechaComienzo(Date fechaComienzo) {
|
||||
this.fechaComienzo = fechaComienzo;
|
||||
}
|
||||
|
||||
public Date getFechaEntrega() {
|
||||
return fechaEntrega;
|
||||
}
|
||||
|
||||
public void setFechaEntrega(Date fechaEntrega) {
|
||||
this.fechaEntrega = fechaEntrega;
|
||||
}
|
||||
|
||||
public int getCodUser() {
|
||||
return codUser;
|
||||
}
|
||||
|
||||
public void setCodUser(int codUser) {
|
||||
this.codUser = codUser;
|
||||
}
|
||||
|
||||
public int getIsbnLibro() {
|
||||
return isbnLibro;
|
||||
}
|
||||
|
||||
public void setIsbnLibro(int isbnLibro) {
|
||||
this.isbnLibro = isbnLibro;
|
||||
}
|
||||
|
||||
public boolean isAltaDemanda() {
|
||||
return altaDemanda;
|
||||
}
|
||||
|
||||
public void setAltaDemanda(boolean altaDemanda) {
|
||||
this.altaDemanda = altaDemanda;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Prestamo{" +
|
||||
"fechaComienzo=" + fechaComienzo +
|
||||
", fechaEntrega=" + fechaEntrega +
|
||||
", codUser=" + codUser +
|
||||
", isbnLibro=" + isbnLibro +
|
||||
", altaDemanda=" + altaDemanda +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
16
src/main/java/examenes/examen20250221/ejercicio04/Main.java
Normal file
16
src/main/java/examenes/examen20250221/ejercicio04/Main.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package examenes.examen20250221.ejercicio04;
|
||||
|
||||
import examenes.examen20250221.ejercicio04.listener.CheckeadorNums;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new Matematico();
|
||||
while (true) {
|
||||
try {
|
||||
CheckeadorNums.solicitarNumMayor100();
|
||||
} catch (NumeroMenor100Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package examenes.examen20250221.ejercicio04;
|
||||
|
||||
|
||||
import examenes.examen20250221.ejercicio04.listener.CheckeadorNums;
|
||||
import examenes.examen20250221.ejercicio04.listener.NumRepetidoEvent;
|
||||
import examenes.examen20250221.ejercicio04.listener.NumsListener;
|
||||
|
||||
public class Matematico implements NumsListener {
|
||||
public Matematico() {
|
||||
CheckeadorNums.addNumRepetidoListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void numeroRepetido(NumRepetidoEvent event) {
|
||||
System.out.println("Soy un Matematico y me he dado cuenta de que has repetido el número " + event.getNumero());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package examenes.examen20250221.ejercicio04;
|
||||
|
||||
public class NumeroMenor100Exception extends Exception {
|
||||
public NumeroMenor100Exception(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package examenes.examen20250221.ejercicio04.listener;
|
||||
|
||||
import examenes.examen20250221.ejercicio04.NumeroMenor100Exception;
|
||||
import examenes.examen20250221.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CheckeadorNums {
|
||||
private static int numAnterior;
|
||||
static List<NumsListener> listeners = new ArrayList<NumsListener>();
|
||||
|
||||
public static void addNumRepetidoListener(NumsListener l) {
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public static void removeNumRepetidoListener(NumsListener l) {
|
||||
listeners.remove(l);
|
||||
}
|
||||
|
||||
private static void fireNumRepetido(int resultado) {
|
||||
for (NumsListener opl : listeners) {
|
||||
opl.numeroRepetido(new NumRepetidoEvent(resultado));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int solicitarNumMayor100() throws NumeroMenor100Exception {
|
||||
int num = Utils.solicitarIntScannerInline("Introduzca un número igual o mayor que 100: ");
|
||||
if (num < 100) throw new NumeroMenor100Exception("El número " + num + " es menor de 100.");
|
||||
if (numAnterior == num) fireNumRepetido(num);
|
||||
numAnterior = num;
|
||||
return num;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package examenes.examen20250221.ejercicio04.listener;
|
||||
|
||||
public class NumRepetidoEvent {
|
||||
private int numero;
|
||||
|
||||
public NumRepetidoEvent(int numero) {
|
||||
this.numero = numero;
|
||||
}
|
||||
|
||||
public int getNumero() {
|
||||
return numero;
|
||||
}
|
||||
|
||||
public void setNumero(int numero) {
|
||||
this.numero = numero;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NumRepetidoEvent{" +
|
||||
"numero=" + numero +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package examenes.examen20250221.ejercicio04.listener;
|
||||
|
||||
public interface NumsListener {
|
||||
|
||||
public void numeroRepetido(NumRepetidoEvent event);
|
||||
}
|
||||
79
src/main/java/examenes/examen20250221/utils/Utils.java
Normal file
79
src/main/java/examenes/examen20250221/utils/Utils.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package examenes.examen20250221.utils;
|
||||
|
||||
import examenes.examen20250221.ejercicio01.Producto;
|
||||
import examenes.examen20250221.ejercicio02.Letra;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Utils {
|
||||
public static int solicitarIntScannerInline(String pregunta) {
|
||||
System.out.print(pregunta);
|
||||
Scanner sc = new Scanner(System.in);
|
||||
return sc.nextInt();
|
||||
}
|
||||
|
||||
public static String solicitarStringScannerInline(String pregunta) {
|
||||
System.out.print(pregunta);
|
||||
Scanner sc = new Scanner(System.in);
|
||||
return sc.nextLine();
|
||||
}
|
||||
|
||||
public static double solicitarDoubleScannerInline(String pregunta) {
|
||||
System.out.print(pregunta);
|
||||
Scanner sc = new Scanner(System.in);
|
||||
return sc.nextDouble();
|
||||
}
|
||||
|
||||
public static List<Producto> ordenarBurbujaProductosPorPrecio(List<Producto> lista) {
|
||||
boolean ordenando;
|
||||
do {
|
||||
ordenando = false;
|
||||
for (int i = 0; i < lista.size(); i++) {
|
||||
if (i != (lista.size() - 1) && lista.get(i).getPrecio() < lista.get(i + 1).getPrecio()) {
|
||||
Producto elementoTemporal = lista.get(i);
|
||||
lista.set(i, lista.get(i + 1));
|
||||
lista.set(i + 1, elementoTemporal);
|
||||
ordenando = true;
|
||||
}
|
||||
}
|
||||
} while (ordenando);
|
||||
return lista;
|
||||
}
|
||||
|
||||
public static List<Letra> ordenarBurbujaLetras(List<Letra> lista) {
|
||||
boolean ordenando;
|
||||
do {
|
||||
ordenando = false;
|
||||
for (int i = 0; i < lista.size(); i++) {
|
||||
if (i != (lista.size() - 1) && lista.get(i).getConteoLetra() < lista.get(i + 1).getConteoLetra()) {
|
||||
Letra elementoTemporal = lista.get(i);
|
||||
lista.set(i, lista.get(i + 1));
|
||||
lista.set(i + 1, elementoTemporal);
|
||||
ordenando = true;
|
||||
}
|
||||
}
|
||||
} while (ordenando);
|
||||
return lista;
|
||||
}
|
||||
|
||||
public static Date solicitarFechaInline(String formato) {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
SimpleDateFormat formatoFecha = new SimpleDateFormat(formato);
|
||||
|
||||
while (true) {
|
||||
System.out.print("Introduzca una fecha con este formato ( " + formato + " ) > ");
|
||||
String fechaIntroducida = sc.nextLine();
|
||||
|
||||
try {
|
||||
return formatoFecha.parse(fechaIntroducida);
|
||||
} catch (ParseException e) {
|
||||
System.out.println("\nVuelva a introducir la fecha, en el formato correcto: " + formato);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user