Пример #1
0
        private static void Test_Offerte()
        {
            List <ProdottoInOfferta> prodotti = new List <ProdottoInOfferta>();

            for (int i = 0; i < 4; i++)
            {
                prodotti.Add(GetProdotto());
            }

            Negozio myNegozio = GetNegozio(prodotti);

            List <ProdottoInOfferta> offerte = new List <ProdottoInOfferta>();
            ProdottoInOfferta        product;

            foreach (var item in myNegozio.Lista_prodotti)
            {
                product = (ProdottoInOfferta)item;
                if (isInOfferta(product))
                {
                    offerte.Add(product);
                }
            }
            Console.WriteLine("Offerte di oggi al negozio {0}:", myNegozio.Nome);
            foreach (var item in offerte)
            {
                Console.WriteLine("{0}: prezzo {1} euro e sconto del {2}%", item.Descrizione, item.Prezzo.ToString(), item.Sconto.ToString());
            }
        }
Пример #2
0
        private static void Test_CreazioneNegozio()
        {
            Console.WriteLine("Test primo costruttore.");
            Console.WriteLine("Inserire Nome Negozio:");
            string nome1 = Console.ReadLine();

            Console.WriteLine("Inserire Nome Proprietario:");
            string nome_prop1 = Console.ReadLine();

            Console.WriteLine("Inserire Cognome Proprietario:");
            string cognome_prop1 = Console.ReadLine();

            Negozio negozio1 = new Negozio(nome1, nome_prop1, cognome_prop1);

            Console.WriteLine("Ho creato il negozio {0}, il cui proprietario è {1} {2}.", negozio1.Nome, negozio1.Proprietario[0], negozio1.Proprietario[1]);
            if (negozio1.Lista_prodotti == null)
            {
                Console.WriteLine("Nel negozio non sono presenti prodotti.");
            }
            else
            {
                Console.WriteLine("Nel negozio sono presenti i seguenti prodotti: ");
                foreach (var prod in negozio1.Lista_prodotti)
                {
                    Console.WriteLine("{0}", prod.Descrizione);
                }
            }

            Console.WriteLine("Test secondo costruttore.");
            Console.WriteLine("Inserire Nome Negozio:");
            string nome2 = Console.ReadLine();

            Console.WriteLine("Inserire Nome Proprietario:");
            string nome_prop2 = Console.ReadLine();

            Console.WriteLine("Inserire Cognome Proprietario:");
            string cognome_prop2 = Console.ReadLine();

            Console.WriteLine("Inserire Prodotto (codice descrizione prezzo sconto):");
            string line = Console.ReadLine();
            char   sep  = ' ';

            string[] dati_prodotto = line.Split(sep);
            Prodotto item          = new Prodotto(Int32.Parse(dati_prodotto[0]), dati_prodotto[1], Double.Parse(dati_prodotto[2]), Double.Parse(dati_prodotto[3]));

            Negozio negozio2 = new Negozio(nome2, nome_prop2, cognome_prop2, item);

            Console.WriteLine("Ho creato il negozio {0}, il cui proprietario è {1} {2}.", negozio2.Nome, negozio2.Proprietario[0], negozio2.Proprietario[1]);
            if (negozio2.Lista_prodotti == null)
            {
                Console.WriteLine("Nel negozio non sono presenti prodotti.");
            }
            else
            {
                Console.WriteLine("Nel negozio sono presenti i seguenti prodotti: ");
                foreach (var prod in negozio2.Lista_prodotti)
                {
                    Console.WriteLine("{0}", prod.Descrizione);
                }
            }

            Console.WriteLine("Test terzo costruttore.");
            Console.WriteLine("Inserire Nome Negozio:");
            string nome3 = Console.ReadLine();

            Console.WriteLine("Inserire Nome Proprietario:");
            string nome_prop3 = Console.ReadLine();

            Console.WriteLine("Inserire Cognome Proprietario:");
            string cognome_prop3 = Console.ReadLine();

            Console.WriteLine("Inserire Prodotti (codice descrizione prezzo sconto), per terminare scrivere 'stop':");

            List <Prodotto> lista_prodotti = new List <Prodotto>();

            while (!(line = Console.ReadLine()).Equals("stop"))
            {
                string[] dati_prod = line.Split(sep);
                Prodotto product   = new Prodotto(Int32.Parse(dati_prod[0]), dati_prod[1], Double.Parse(dati_prod[2]), Double.Parse(dati_prod[3]));
                lista_prodotti.Add(product);
            }
            Negozio negozio3 = new Negozio(nome3, nome_prop3, cognome_prop3, lista_prodotti);

            Console.WriteLine("Ho creato il negozio {0}, il cui proprietario è {1} {2}.", negozio3.Nome, negozio3.Proprietario[0], negozio3.Proprietario[1]);
            if (negozio3.Lista_prodotti == null)
            {
                Console.WriteLine("Nel negozio non sono presenti prodotti.");
            }
            else
            {
                Console.WriteLine("Nel negozio sono presenti i seguenti prodotti: ");
                foreach (var item2 in negozio3.Lista_prodotti)
                {
                    Console.WriteLine("{0},", item2.Descrizione);
                }
            }
        }
Пример #3
0
        private static void TestProdotti()
        {
            Console.WriteLine("Inserisci il nome del negozio: ");
            string nome_negozio = Console.ReadLine();

            Console.WriteLine("Inserisci il proprietario del negozio: ");
            string prop = Console.ReadLine();

            Console.WriteLine("Inserisci prodotto/i: ");
            string          line          = "";
            int             counter       = 0;
            List <Prodotto> ListaProdotti = new List <Prodotto>();

            while (line != null && counter < 2)
            {
                line = Console.ReadLine();
                String[] res = line.Split(new char[] { ' ' });

                if (res.Length == 1)
                {
                    Prodotto prodotto = new Prodotto(res[0]);

                    ListaProdotti.Add(prodotto);
                }

                if (res.Length == 2)
                {
                    int      cod      = Convert.ToInt32(res[0]);
                    Prodotto prodotto = new Prodotto(cod, res[1]);

                    ListaProdotti.Add(prodotto);
                }

                if (res.Length == 3)
                {
                    double   price    = Convert.ToDouble(res[1]);
                    double   discount = Convert.ToDouble(res[2]);
                    Prodotto prodotto = new Prodotto(res[0], price, discount);

                    ListaProdotti.Add(prodotto);
                }

                if (res.Length == 4)
                {
                    int      cod      = Convert.ToInt32(res[0]);
                    double   price    = Convert.ToDouble(res[2]);
                    double   discount = Convert.ToDouble(res[3]);
                    Prodotto prodotto = new Prodotto(cod, res[1], price, discount);

                    ListaProdotti.Add(prodotto);
                }
                counter++;
            }

            Negozio neg = new Negozio(nome_negozio, prop, ListaProdotti);

            Console.WriteLine("\r\nIl negozio {0} di {1} ha i seguenti prodotti:", neg.Nome, neg.Proprietario);
            foreach (Prodotto c2 in ListaProdotti)
            {
                System.Console.Write(c2.ToString());
                Console.WriteLine("\r\n");
            }
            System.Console.ReadLine();
        }