public Getränk[] Auffüllen()
        {
            int Zähler = 0;

            String[,] GetränkeListe = new string[7, 2]
            {
                { "Cola", "1,50" },
                { "Fanta", "1,20" },
                { "Sprite", "1,20" },
                { "Wasser", "1,00" },
                { "Bier", "2,00" },
                { "Ice Tea", "1,20" },
                { "Kölsch", "1,00" }
            };

            Getränk[] Getränke = new Getränk[GetränkeListe.GetLength(0)];

            for (int i = 0; i < GetränkeListe.GetLength(0); i++)
            {
                for (int j = 0; j < GetränkeListe.GetLength(1); j++)
                {
                    Getränk G = new Getränk(GetränkeListe[i, j], Convert.ToDouble(GetränkeListe[i, j + 1]));
                    Getränke[Zähler] = G;
                    Zähler++;
                    j++;
                }
            }
            return(Getränke);
        }
Пример #2
0
        static void Main(string[] args)
        {
            bool Schalter = true;
            int  Auswahl;
            int  Länge = -1;

            Getränk[] AuswahListe = new Getränk[15];
            Getränk   Wahl;

            // Erstellen des Getränke Automatens und Aufüllen mit Getränken
            Getränkeautomat ColaAutomat = new Getränkeautomat();

            Getränk[] Inhalt = ColaAutomat.Auffüllen();

            // Festlegung der Länge des Arrays Inhalt
            foreach (Getränk i in Inhalt)
            {
                Länge++;
            }

            //Auswahal von Getränken und Bezalvorgang.
            while (Schalter)
            {
                Console.WriteLine("Herzlich Wilkommen: \n"
                                  + "Bitte wählen sie ihr Getränk:");
                for (int i = 0; i < Inhalt.Length; i++)
                {
                    Console.WriteLine("[" + i + "]" + Inhalt[i].printArt() + " Preis: {0:0.00} Euro", Inhalt[i].printPreis());
                }

                Console.WriteLine("Bitte Auswahl treffen: ");
                Auswahl = Convert.ToInt16(Console.ReadLine());


                if ((Auswahl >= 0) && (Auswahl <= Länge))
                {
                    Wahl = Inhalt[Auswahl];
                    Console.WriteLine("Sie haben " + Wahl.printArt() + " Gewählt bitte Werfen sie {0:0.00} Euro in den Automaten.", Wahl.printPreis());
                    ColaAutomat.Bezahlen(Wahl);
                }

                //Beenden des Automatens

                else if (Auswahl == 100)
                {
                    Schalter = false;
                    Console.WriteLine("Automat wird Beendet");
                    Console.ReadKey();
                }

                else
                {
                    Console.WriteLine("Sie haben kein Getränk geaählt Vorgang Abgebrochen.");
                    Console.ReadKey();
                }
                Console.Clear();
            }
        }
        public void Bezahlen(Getränk Objekt)
        {
            double Preis         = Objekt.printPreis();
            int    Auswahl       = 0;
            int    ZaehlerCent1  = 0;
            int    ZaehlerCent2  = 0;
            int    ZaehlerCent5  = 0;
            int    ZaehlerCent10 = 0;
            int    ZaehlerCent20 = 0;
            int    ZaehlerCent50 = 0;
            int    ZaehlerEuro1  = 0;
            int    ZaehlerEuro2  = 0;

            Console.WriteLine("Bitte Geld einwerfen: \n"
                              + "[1]  1 cent \n"
                              + "[2]  2 cent \n"
                              + "[3]  5 cent \n"
                              + "[4] 10 cent \n"
                              + "[5] 20 cent \n"
                              + "[6] 50 cent \n"
                              + "[7]  1 Euro \n"
                              + "[8]  2 Euro \n"
                              + "[9] Abbruch");


            while (Preis > 0)
            {
                Auswahl = Convert.ToInt16(Console.ReadLine());


                if (Auswahl == 1)
                {
                    Preis -= 0.01;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerCent1 += 1;
                }

                else if (Auswahl == 2)
                {
                    Preis -= 0.02;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerCent2 += 1;
                }

                else if (Auswahl == 3)
                {
                    Preis -= 0.05;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerCent5 += 1;
                }

                else if (Auswahl == 4)
                {
                    Preis -= 0.1;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerCent10 += 1;
                }

                else if (Auswahl == 5)
                {
                    Preis -= 0.2;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerCent20 += 1;
                }

                else if (Auswahl == 6)
                {
                    Preis -= 0.5;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerCent50 += 1;
                }

                else if (Auswahl == 7)
                {
                    Preis -= 1.0;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerEuro1 += 1;
                }

                else if (Auswahl == 8)
                {
                    Preis -= 2.0;
                    Preis  = Math.Round(Preis, 2);
                    Console.WriteLine(Preis);
                    ZaehlerEuro2 += 1;
                }

                else if (Auswahl == 9)
                {
                    break;
                }
            }

            if (Auswahl != 9)
            {
                Cent1  += ZaehlerCent1;
                Cent2  += ZaehlerCent2;
                Cent5  += ZaehlerCent5;
                Cent10 += ZaehlerCent10;
                Cent20 += ZaehlerCent20;
                Cent50 += ZaehlerCent50;
                Euro1  += ZaehlerEuro1;
                Euro2  += ZaehlerEuro2;

                if (Preis < 0)
                {
                    Wechselgeld(Preis);
                }

                Console.WriteLine("Vielen Dank für ihren Einkauf \n"
                                  + Objekt.printArt() + " fällt aus dem Automaten");

                Console.ReadKey();
            }
        }