コード例 #1
0
        /* OPPGAVE D*/
        public Sittebillett[] KjøpBillett(int antVoksne, int antBarn)
        {
            bool         kanSelges = this.SelgPlasser(antBarn + antVoksne).Key;
            Sittebillett n         = this.SelgPlasser(antBarn + antVoksne).Value;
            int          antall    = antBarn + antVoksne;

            if (kanSelges)
            {
                Sittebillett[] temp   = new Sittebillett[antall];
                int            teller = n.plassnr + 1;
                for (int i = 0; i < antVoksne; i++)
                {
                    Sittebillett b = new Sittebillett(Navn, this.Pris, n.rad, teller);
                    temp[i]  = b;
                    inntekt += Pris;
                }
                for (int j = antVoksne; j < temp.Length; j++)
                {
                    Sittebillett barneBillett = this.SelgPlasser(antBarn).Value;
                    temp[j]  = barneBillett;
                    inntekt += Barnepris;
                }
                Console.WriteLine("[" + this.Navn + "]: Kvittering: " + antall + " billetter solgt");
                return(temp);
            }
            else
            {
                Console.WriteLine("[" + this.Navn + "]: Oppgitt antall (" + antall + ") billetter kan ikke selges på same rad, prøv et nytt tall.");
                return(null);
            }
        }
コード例 #2
0
        // OPPGAVE D start

        virtual public Billett[] KjøpBillett(String[] listeVoksne, String[] listeBarn)
        {
            bool kanSelges = false;

            if (listeBarn != null || listeVoksne != null)
            {
                if (listeVoksne.Length != 0 || listeBarn.Length != 0)
                {
                    kanSelges = this.SelgPlasser(listeBarn.Length + listeVoksne.Length).Key;
                }
            }
            int antall = 0;

            if (listeVoksne != null)
            {
                antall += listeVoksne.Length;
            }
            if (listeBarn != null)
            {
                antall += listeBarn.Length;
            }

            Sittebillett n = this.SelgPlasser(antall).Value;

            //int antall = listeBarn.Length + listeVoksne.Length;
            if (kanSelges)
            {
                Billett[] temp   = new Sittebillett[antall];
                int       teller = n.plassnr + 1;
                for (int i = 0; i < listeVoksne.Length; i++)
                {
                    Sittebillett b = new Sittebillett(Navn, this.Pris, n.rad, teller);
                    temp[i]  = b;
                    inntekt += Pris;
                }
                for (int j = listeVoksne.Length; j < temp.Length; j++)
                {
                    Sittebillett barneBillett = this.SelgPlasser(listeBarn.Length).Value;
                    temp[j]  = barneBillett;
                    inntekt += Barnepris;
                }
                Console.WriteLine("[" + this.Navn + "]: Kvittering: " + antall + " billetter solgt");
                return(temp);
            }
            else
            {
                if (antall > 0)
                {
                    Console.WriteLine("[" + this.Navn + "]: Oppgitt antall (" + antall + ") billetter kan ikke selges på same rad, prøv et nytt tall.");
                }
                else if (antall == 0)
                {
                    Console.WriteLine("[" + this.Navn + "] Bestillingensliste er tom, ingen kjøp er registrert, prøv igjen");
                }
                return(null);
            }
        }