mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
feat(test 20250221): solved
This commit is contained in:
65
src/tutorialJava/examenes/examen20250221/EjercicioC.java
Normal file
65
src/tutorialJava/examenes/examen20250221/EjercicioC.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package tutorialJava.examenes.examen20250221;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import tutorialJava.Utils;
|
||||
|
||||
public class EjercicioC {
|
||||
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Date fechaDevolucion = pideFecha();
|
||||
int tipoDemanda = Utils.obtenerEnteroConDescripcion(
|
||||
"Tipo de demanda (1.- normal - 2.- alta):");
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(fechaDevolucion);
|
||||
|
||||
// Calcula la fecha de devolución
|
||||
if (tipoDemanda == 1) cal.add(Calendar.DAY_OF_YEAR, 15);
|
||||
else cal.add(Calendar.DAY_OF_YEAR, 7); // Alta demanda
|
||||
|
||||
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
|
||||
cal.add(Calendar.DAY_OF_YEAR, 2);
|
||||
else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
|
||||
// Muestra fecha devolución
|
||||
Date dateDevolucion = new Date(cal.getTimeInMillis());
|
||||
System.out.println("Fecha devolución: " + sdf.format(dateDevolucion));
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Fecha inválida");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Date pideFecha() throws Exception {
|
||||
String strFecha =
|
||||
Utils.obtenerCadenaConDescripcion("Dame la fecha de préstamo dd/MM/yyyy:");
|
||||
return sdf.parse(strFecha);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user