Advertisement
LaCaraDeLaVerga

SOLUCION JERE MACHO ALPHA

Nov 20th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1. package NEGOCIOACTUAL;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import javax.swing.JOptionPane;
  6.  
  7. public class Solucion {
  8.  
  9.     private static Oferta dia[];
  10.     private static ArrayList<Oferta> ofertas;
  11.  
  12.     public Solucion() {
  13.         dia = new Oferta[24];
  14.         ofertas = new ArrayList<Oferta>();
  15.     }
  16.  
  17.     public Oferta[] getDia() {
  18.         return dia;
  19.     }
  20.  
  21.     public void setDia(Oferta[] arr) {
  22.        
  23.         dia = arr;
  24.     }
  25.  
  26.     public boolean aceptarOferta(Oferta nueva) {
  27.         if (nueva.horaEntrada >= 24 || nueva.horaSalida >= 24) {
  28.             JOptionPane.showMessageDialog(null, "Hora fuera de rango , los dias no tienen mas de 24 horas ");
  29.             return false;
  30.         }
  31.         if (nueva.horaEntrada - nueva.horaSalida == 0) {
  32.             JOptionPane.showMessageDialog(null, "debe reservar como minimo una hora completa , intente nuevamente");
  33.             return false;
  34.         }
  35.         if (nueva.horaEntrada - nueva.horaSalida > 0) {
  36.             JOptionPane.showMessageDialog(null,"la reserva no puede abarcar dos dias distintos , intente nuevamente");
  37.             return false;  
  38.         }
  39.  
  40.         solverGoloso(nueva);
  41.         return true;
  42.     }
  43.  
  44.     public static void solverGoloso(Oferta nueva){
  45.        
  46.         if (horasDisponibles(nueva)) {
  47.             ofertaAceptada(nueva);
  48.         }else{
  49.             if(!mejorOpcion(nueva)){
  50.                 JOptionPane.showMessageDialog(null,"su oferta no fue registrada pobre asqueroso");
  51.                 for (int i = 0; i < dia.length; i++) {
  52.                     if (dia[i]==null) {
  53.                         System.out.println("null");
  54.                        
  55.                     }else{
  56.                         dia[i].getNombre();
  57.                     }
  58.                    
  59.                 }
  60.             }
  61.         }
  62.             if (mejorOpcion(nueva)) {
  63.                 liberarHoras();
  64.                 ofertaAceptada(nueva); 
  65.             }
  66.     }
  67.            
  68.  
  69.        
  70.     private static boolean mejorOpcion(Oferta nueva){
  71.         //ofertas.clear();
  72.         ofertas = new ArrayList<Oferta>();
  73.         boolean ret = true ;
  74.         double dinero =0;
  75.             for (int i = nueva.horaEntrada; i < nueva.horaSalida; i++) {
  76.                 if (dia[i]!=null && !ofertas.contains(dia[i])) {
  77.                     ofertas.add(dia[i]);
  78.                     dinero +=dia[i].dinero;
  79.                 }
  80.                 if (dinero >= nueva.dinero ) {
  81.                     return false ;
  82.                 }
  83.             }
  84.         return ret ;
  85.    
  86.     }
  87.            
  88.     private static void ofertaAceptada(Oferta nueva) {
  89.         for (int i = nueva.horaEntrada; i < nueva.horaSalida; i++) {
  90.              dia[i]= nueva ;       
  91.         }
  92.         JOptionPane.showMessageDialog(null,"Su oferta ingreso correctmente");
  93.        
  94.         for (int i = 0; i < dia.length; i++) {
  95.             System.out.println(dia[i]);
  96.         }
  97.     }
  98.  
  99.     public static boolean horasDisponibles(Oferta nueva){
  100.     boolean ret = true;
  101.  
  102.             for (int i = nueva.horaEntrada; i < nueva.horaSalida; i++) {   
  103.                     if (dia[i]!=null) {
  104.                         ret = false ;
  105.                     }
  106.             }
  107.     return ret ;
  108.     }
  109.    
  110.     static boolean verificarNull(Oferta oferta1, Oferta oferta2){
  111.         if(oferta1 == null || oferta2 == null){
  112.             return false;
  113.         }
  114.         return true;
  115.     }
  116.  
  117.     static void liberarHoras() {
  118.  
  119.         for (Oferta oferta : ofertas) {
  120.  
  121.             for (Oferta ofertaDia : dia) {
  122.                 if (verificarNull(oferta, ofertaDia) == true) {
  123.                     if (ofertaDia.equals(oferta)) {
  124.  
  125.                         ofertaDia = null;
  126.                     }
  127.                 }
  128.             }
  129.         }
  130.         ofertas = null;
  131.     }
  132. //FIN DE LA CLASE--------------------------------------------------------------------------------------------->>
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement