Package it.unisa.info13d.Login

Examples of it.unisa.info13d.Login.Entry


   * @throws IOException
   * @throws ClassNotFoundException
   * @throws FileNotFoundException
   */
  public static void showClientMenu(Catalogo catalogo, ReShow r, String username) throws FileNotFoundException, ClassNotFoundException, IOException {
    Entry loggedUser = Access.get_user_data(username);
    System.out.println("------------ Menu operazioni ------------");
    System.out.println("-- Salto totale:"+loggedUser.getBalance());
    System.out.println("1 --> Acquista Credito");       //Si acquista credito per l'acquisto dei prodotti
    System.out.println("2 --> Visualizza Offerte");     //Visualizza le offerte acquistabili
    System.out.println("3 --> Acquista");               //Acquisto di un offerta
    System.out.println("4 --> Storico acquisti");       //Visualizza lo storico degli acquisti dell'utente
    System.out.println("5 --> Esci");
View Full Code Here


   * @throws ClassNotFoundException
   * @throws IOException
   */
  public void offerteAttive(String user) throws FileNotFoundException, ClassNotFoundException, IOException
  {
    Entry loggedUser = Access.get_user_data(user);
    if(!(loggedUser.getType()))
    {
            Scanner reader = new Scanner(System.in);


            System.out.println("1 --> Ordina Per Data di Scadenza");
            System.out.println("2 --> Ordina Per ID");

            String choice;
            System.out.print("Scelta operazione: ");
            choice = reader.nextLine();
            for ( ;  !(choice.equals("1")) && !(choice.equals("2"))  ;){
                System.out.println("Scelta Errata. Riprovare");
                System.out.print("Scelta operazione: ");
                choice = reader.nextLine();
            }

            if  (choice.equals("1")){

                class CompareDataScadenza implements Comparator<Utilizzabile> {

                    @Override
                    public int compare(Utilizzabile e1, Utilizzabile e2) {

                      if (e1 instanceof BeniDiConsumo){
                           //beni vs
                            if (e2 instanceof Vacanze){
                                //beni vs vacanze
                                if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis())
                                    return -1;
                                    return 1;

                            }else{
                                if (e2 instanceof BeniDiConsumo){
                                    //bene vs //bene

                                    if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis())
                                        return -1;
                                    return 1;

                                }else{
                                    //bene vs cena

                                    if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis())
                                        return -1;
                                    return 1;
                                }
                            }
                      }else{
                          if (e1 instanceof Vacanze){
                               //vacanze vs
                              if (e2 instanceof BeniDiConsumo){
                                  //vacanze vs bene
                                  if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis())
                                      return -1;
                                  return 1;

                              }else{
                                  if (e2 instanceof Vacanze){
                                      //vacabnza vs vacanza

                                      if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis())
                                          return -1;
                                      return 1;


                                  }else{
                                      //vacanza vs cena

                                      if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis())
                                          return -1;
                                      return 1;

                                  }
                              }

                          }else{
                              //Cene vs
                              if (e2 instanceof Vacanze){
                                  //cena vs vacanza

                                  if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis())
                                      return -1;
                                  return 1;

                              }else{
                                  if (e2 instanceof CeneInRistoranti){
                                      //cena vs cena

                                      if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis())
                                          return -1;
                                      return 1;
                                  }else{
                                      //cena vs bene

                                      if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis())
                                          return -1;
                                      return 1;
                                  }
                              }

                          }
                      }

                    }
                }

                Collections.sort(catalogoOfferte,new CompareDataScadenza());
                print_cat_admin (catalogoOfferte);
            }else{

                class CompareID implements Comparator<Utilizzabile> {

                    @Override
                    public int compare(Utilizzabile e1, Utilizzabile e2) {

                        if (e1 instanceof BeniDiConsumo){
                            //beni vs
                            if (e2 instanceof Vacanze){
                                //beni vs vacanze
                                if (((BeniDiConsumo)e1).getIdBene() < ((Vacanze)e2).getIdViaggio())
                                    return -1;
                                return 1;

                            }else{
                                if (e2 instanceof BeniDiConsumo){
                                    //bene vs //bene

                                    if (((BeniDiConsumo)e1).getIdBene() < ((BeniDiConsumo)e2).getIdBene())
                                        return -1;
                                    return 1;

                                }else{
                                    //bene vs cena

                                    if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena())
                                        return -1;
                                    return 1;
                                }
                            }
                        }else{
                            if (e1 instanceof Vacanze){
                                //vacanze vs
                                if (e2 instanceof BeniDiConsumo){
                                    //vacanze vs bene
                                    if (((Vacanze)e1).getIdViaggio() < ((BeniDiConsumo)e2).getIdBene())
                                        return -1;
                                    return 1;

                                }else{
                                    if (e2 instanceof Vacanze){
                                        //vacabnza vs vacanza

                                        if (((Vacanze)e1).getIdViaggio() < ((Vacanze)e2).getIdViaggio())
                                            return -1;
                                        return 1;


                                    }else{
                                        //vacanza vs cena

                                        if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena())
                                            return -1;
                                        return 1;

                                    }
                                }

                            }else{
                                //Cene vs
                                if (e2 instanceof Vacanze){
                                    //cena vs vacanza

                                    if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio())
                                        return -1;
                                    return 1;

                                }else{
                                    if (e2 instanceof CeneInRistoranti){
                                        //cena vs cena

                                        if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena())
                                            return -1;
                                        return 1;
                                    }else{
                                        //cena vs bene

                                        if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene())
                                            return -1;
                                        return 1;
                                    }
                                }

                            }
                        }

                    }
                }


                Collections.sort(catalogoOfferte,new CompareID());
                print_cat_admin (catalogoOfferte);

            }


    } else{

            class CompareIDUser implements Comparator<Utilizzabile> {

                @Override
                public int compare(Utilizzabile e1, Utilizzabile e2) {

                    if (e1 instanceof BeniDiConsumo){
                        //beni vs
                        if (e2 instanceof Vacanze){
                            //beni vs vacanze
                            if (((BeniDiConsumo)e1).getIdBene() < ((Vacanze)e2).getIdViaggio())
                                return -1;
                            return 1;

                        }else{
                            if (e2 instanceof BeniDiConsumo){
                                //bene vs //bene

                                if (((BeniDiConsumo)e1).getIdBene() < ((BeniDiConsumo)e2).getIdBene())
                                    return -1;
                                return 1;

                            }else{
                                //bene vs cena

                                if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena())
                                    return -1;
                                return 1;
                            }
                        }
                    }else{
                        if (e1 instanceof Vacanze){
                            //vacanze vs
                            if (e2 instanceof BeniDiConsumo){
                                //vacanze vs bene
                                if (((Vacanze)e1).getIdViaggio() < ((BeniDiConsumo)e2).getIdBene())
                                    return -1;
                                return 1;

                            }else{
                                if (e2 instanceof Vacanze){
                                    //vacabnza vs vacanza

                                    if (((Vacanze)e1).getIdViaggio() < ((Vacanze)e2).getIdViaggio())
                                        return -1;
                                    return 1;


                                }else{
                                    //vacanza vs cena

                                    if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena())
                                        return -1;
                                    return 1;

                                }
                            }

                        }else{
                            //Cene vs
                            if (e2 instanceof Vacanze){
                                //cena vs vacanza

                                if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio())
                                    return -1;
                                return 1;

                            }else{
                                if (e2 instanceof CeneInRistoranti){
                                    //cena vs cena

                                    if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena())
                                        return -1;
                                    return 1;
                                }else{
                                    //cena vs bene

                                    if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene())
                                        return -1;
                                    return 1;
                                }
                            }

                        }
                    }

                }
            }


            Collections.sort(catalogoOfferte,new CompareIDUser());
            print_cat_user(catalogoOfferte,loggedUser.getLocation());

        }
  }
View Full Code Here

   * @throws ClassNotFoundException
   * @throws FileNotFoundException
   */
  public void offerteScadute(String user) throws FileNotFoundException, ClassNotFoundException, IOException
  {
    Entry loggedUser = Access.get_user_data(user);
    System.out.println("------ Offerte Scadute -----");
    for(Utilizzabile deal: catalogoOfferte)
    {
      if(deal instanceof Vacanze)
      {
View Full Code Here

   * @throws ClassNotFoundException
   * @throws IOException
   */
  public void aggiungiCredito(String user) throws FileNotFoundException, ClassNotFoundException, IOException
  {
    Entry loggedUser = Access.get_user_data(user);
    System.out.println("----- Acquisto Credito -----");
    System.out.println("Saldo Attuale:"+ loggedUser.getBalance());
    System.out.println("Aggiungi importo da ricaricare:");
    Scanner inputData = new Scanner(System.in);
    String euro = inputData.nextLine();
    loggedUser.setBalance(Double.parseDouble(euro));
    Access.replace_data(user, loggedUser);
    System.out.println("Saldo attuale: "+loggedUser.getBalance());
  }
View Full Code Here

   * @throws ClassNotFoundException
   * @throws IOException
   */
  public void acquistaProdotto(String user) throws FileNotFoundException, ClassNotFoundException, IOException
  {
    Entry loggedUser = Access.get_user_data(user);
    System.out.println("----- Shop ----");
    System.out.println("### Prodotti ###");
   
    offerteAttive(user);
   
    System.out.println("Offerta da acquistare[inserisci id]: ");
    Scanner inputData = new Scanner(System.in);
    String idProd = inputData.nextLine();
    int idDel = Integer.parseInt(idProd);
   
    boolean trovato=false;
    ArrayList<StoricoItem> storico = loggedUser.getStorico();
   
    for(Utilizzabile dealsc: catalogoOfferte)
    {
      if((dealsc instanceof Vacanze) && ((Vacanze)dealsc).getIdViaggio()==idDel)
      {
        Vacanze dealVacanza = (Vacanze)dealsc;
        if(dealVacanza.eAcquistabile() && loggedUser.getBalance()>=dealVacanza.getPrezzoPSingola())
        {
          trovato=true;
          storico.add(new StoricoItem("Viaggio: "+dealVacanza.getLocalitaViaggio(), new GregorianCalendar() ,dealVacanza.getPrezzoPSingola()));
          dealVacanza.setViaggiVenduti();
          loggedUser.setBalance((dealVacanza.getPrezzoPSingola() * (-1)));
          store_data();
          Access.replace_data(user, loggedUser);
          System.out.println("************************************\nAcquisto completato con successo! \n************************************\nSaldo Attuale:" + loggedUser.getBalance());
        }
        else
        {
          System.out.println("Il prodotto non e' acquistabile e/o Credito insufficiente, ricaricare");
          trovato=true;
          break;
       
      }
      if((dealsc instanceof BeniDiConsumo) && ((BeniDiConsumo) dealsc).getIdBene()==idDel)
      {
        BeniDiConsumo dealBene = (BeniDiConsumo)dealsc;
        if(dealBene.eAcquistabile() && loggedUser.getBalance()>=dealBene.getPrezzoBene())
        {
          trovato=true;
          storico.add(new StoricoItem("Prodotto: "+dealBene.getDescrizioneBene(), new GregorianCalendar() ,dealBene.getPrezzoBene()));
          dealBene.setBeniVenduti();
          loggedUser.setBalance((dealBene.getPrezzoBene() * (-1)));
          Access.replace_data(user, loggedUser);
          store_data();
          System.out.println("************************************\nAcquisto completato con successo! \n************************************\nSaldo Attuale:" + loggedUser.getBalance());
        }
        else
        {
          System.out.println("Il prodotto non e' acquistabile e/o Credito insufficiente, ricaricare");
          trovato=true;
          break;
        }
       
      }
      if( (dealsc instanceof CeneInRistoranti) && ((CeneInRistoranti) dealsc).getIdCena()==idDel)
      {
        CeneInRistoranti dealCena = (CeneInRistoranti)dealsc;
        if(dealCena.eAcquistabile() && loggedUser.getBalance()>=dealCena.getCostoPerPersona())
        {
          trovato=true;
          storico.add(new StoricoItem("Cena ristorante "+dealCena.getNomeRistorante()+" "+dealCena.getDescrizione_cena(), new GregorianCalendar() ,dealCena.getCostoPerPersona()));
          dealCena.setCeneVendute();
          loggedUser.setBalance((dealCena.getCostoPerPersona() * (-1)));
          Access.replace_data(user, loggedUser);
          store_data();
          System.out.println("*************************************\nAcquisto completato con successo! \n************************************\nSaldo Attuale:" + loggedUser.getBalance());
        }
        else
        {
          System.out.println("Il prodotto non e' acquistabile e/o Credito insufficiente, ricaricare");
          trovato=true;
View Full Code Here

TOP

Related Classes of it.unisa.info13d.Login.Entry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.