Advertisement
Guest User

Codigo

a guest
Jan 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. package u4ejercicio1;
  2.  
  3. import java.text.DateFormat;
  4. import java.text.ParseException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import javax.swing.JOptionPane;
  8.  
  9. public class U4Ejercicio1 {
  10.  
  11. private static Suscripcion suscripcion[] = new Suscripcion[2];
  12. private static int numeroSusc = 0;
  13. private static int valor;
  14.  
  15. public static void main(String[] args) throws ParseException {
  16.  
  17. //cargaVector();
  18. buscarFecha(suscripcion, 2);
  19.  
  20. }
  21.  
  22. private static void cargaVector() throws ParseException {
  23. String numSusc;
  24. String nombreApell;
  25.  
  26. String localidad;
  27. String codPostal;
  28.  
  29. String fechaIni;
  30. String fechaFin;
  31.  
  32. double precio;
  33.  
  34. for (int i = 0; i < suscripcion.length; i++) {
  35. String entrada;
  36. numSusc = JOptionPane.showInputDialog("Introduce el numero de la suscripcion, por favor: ");
  37. nombreApell = JOptionPane.showInputDialog("Introduce el nombre y los apellidos, por favor: ");
  38. localidad = JOptionPane.showInputDialog("Introduce la localidad, por favor: ");
  39. codPostal = JOptionPane.showInputDialog("Introduce el codigo porstal, por favor: ");
  40.  
  41. fechaIni = JOptionPane.showInputDialog("Introduce la fecha de inicio de la sucripcion, por favor: ");
  42. fechaFin = JOptionPane.showInputDialog("Introduce la fecha de fin de la suscripcion, por favor: ");
  43. DateFormat fecha = new SimpleDateFormat("MM/YYYY");
  44. Date fechaIn = fecha.parse(fechaIni);
  45. Date fechaFn = fecha.parse(fechaFin);
  46.  
  47. entrada = JOptionPane.showInputDialog("Introduce el precio, por favor: ");
  48. precio = Double.parseDouble(entrada);
  49. suscripcion[numeroSusc++] = new Suscripcion(numSusc, nombreApell, localidad, codPostal, fechaIn, fechaFn, precio);
  50. }
  51.  
  52. }
  53.  
  54. private static void buscarFecha(Suscripcion suscripcion[], int num_elementos) throws ParseException {
  55. String fechaBusq;
  56. double precioTotal = 0;
  57.  
  58. fechaBusq = JOptionPane.showInputDialog("Introduce la fecha a buscar: ");
  59. DateFormat fecha = new SimpleDateFormat("MM/YYYY");
  60. Date fechaBusqParsed = fecha.parse(fechaBusq);
  61. for (int i = 0; i < suscripcion.length; i++) {
  62. if (suscripcion[i].getFechaIni().before(fechaBusqParsed)) {
  63. System.out.println(suscripcion[i]);
  64. precioTotal += suscripcion[i].getPrecio();
  65.  
  66. } else {
  67. System.out.println("No hay suscripciones");
  68. }
  69.  
  70. }
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement