Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package u4ejercicio1;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import javax.swing.JOptionPane;
- public class U4Ejercicio1 {
- private static Suscripcion suscripcion[] = new Suscripcion[2];
- private static int numeroSusc = 0;
- private static int valor;
- public static void main(String[] args) throws ParseException {
- //cargaVector();
- buscarFecha(suscripcion, 2);
- }
- private static void cargaVector() throws ParseException {
- String numSusc;
- String nombreApell;
- String localidad;
- String codPostal;
- String fechaIni;
- String fechaFin;
- double precio;
- for (int i = 0; i < suscripcion.length; i++) {
- String entrada;
- numSusc = JOptionPane.showInputDialog("Introduce el numero de la suscripcion, por favor: ");
- nombreApell = JOptionPane.showInputDialog("Introduce el nombre y los apellidos, por favor: ");
- localidad = JOptionPane.showInputDialog("Introduce la localidad, por favor: ");
- codPostal = JOptionPane.showInputDialog("Introduce el codigo porstal, por favor: ");
- fechaIni = JOptionPane.showInputDialog("Introduce la fecha de inicio de la sucripcion, por favor: ");
- fechaFin = JOptionPane.showInputDialog("Introduce la fecha de fin de la suscripcion, por favor: ");
- DateFormat fecha = new SimpleDateFormat("MM/YYYY");
- Date fechaIn = fecha.parse(fechaIni);
- Date fechaFn = fecha.parse(fechaFin);
- entrada = JOptionPane.showInputDialog("Introduce el precio, por favor: ");
- precio = Double.parseDouble(entrada);
- suscripcion[numeroSusc++] = new Suscripcion(numSusc, nombreApell, localidad, codPostal, fechaIn, fechaFn, precio);
- }
- }
- private static void buscarFecha(Suscripcion suscripcion[], int num_elementos) throws ParseException {
- String fechaBusq;
- double precioTotal = 0;
- fechaBusq = JOptionPane.showInputDialog("Introduce la fecha a buscar: ");
- DateFormat fecha = new SimpleDateFormat("MM/YYYY");
- Date fechaBusqParsed = fecha.parse(fechaBusq);
- for (int i = 0; i < suscripcion.length; i++) {
- if (suscripcion[i].getFechaIni().before(fechaBusqParsed)) {
- System.out.println(suscripcion[i]);
- precioTotal += suscripcion[i].getPrecio();
- } else {
- System.out.println("No hay suscripciones");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement