Beispiel #1
0
        public static Sausage operator +(Sausage sausageOne, Sausage sausageTwo)
        {
            DateTime newDateOfExpiry;
            Sausage  sausageToReturn;

            if (sausageOne.DateOfExpiry < sausageTwo.DateOfExpiry)
            {
                newDateOfExpiry = sausageOne.DateOfExpiry;
            }
            else
            {
                newDateOfExpiry = sausageTwo.DateOfExpiry;
            }

            if (sausageOne._sausageType == sausageTwo._sausageType)
            {
                sausageToReturn = new Sausage(sausageTwo._sausageType, newDateOfExpiry, sausageOne.Weight + sausageTwo.Weight);
            }
            else if (sausageOne._sausageType == SausageType.LeberKaese || sausageTwo._sausageType == SausageType.LeberKaese)
            {
                sausageToReturn = new Sausage(SausageType.LeberKaese, newDateOfExpiry, sausageOne.Weight + sausageTwo.Weight);
            }
            else
            {
                sausageToReturn = new Sausage(SausageType.Faschiertes, newDateOfExpiry, sausageOne.Weight + sausageTwo.Weight);
            }
            return(sausageToReturn);
        }
Beispiel #2
0
        public int GetPos(Sausage sausage)
        {
            int position = -1;

            if (_listOfSausages.Contains(sausage))
            {
                position = _listOfSausages.IndexOf(sausage);
            }
            return(position);
        }
Beispiel #3
0
 public Sausage this[SausageType sausageType]
 {
     get
     {
         Sausage sausageToReturn = null;
         foreach (Sausage sausage in _listOfSausages)
         {
             if (sausage.SausageType == sausageType)
             {
                 sausageToReturn = sausage;
                 break;
             }
         }
         return(sausageToReturn);
     }
 }
Beispiel #4
0
 public void Add(Sausage sausage)
 {
     if (_listOfSausages.Count == 0)
     {
         _listOfSausages.Add(sausage);
     }
     else
     {
         foreach (Sausage sausageInList in _listOfSausages)
         {
             if (sausage.SausageType < sausageInList.SausageType)
             {
                 _listOfSausages.Insert(_listOfSausages.IndexOf(sausageInList), sausage);
                 return;
             }
         }
         _listOfSausages.Add(sausage);
     }
 }
Beispiel #5
0
        public Sausage CutFromSausage(SausageType sausageType, double weight)
        {
            Sausage newSausage     = null;
            double  maxWeight      = weight;
            bool    isFirstSausage = true;

            do
            {
                if (isFirstSausage)
                {
                    foreach (Sausage sausage in _listOfSausages)
                    {
                        if (sausage.SausageType == sausageType)
                        {
                            if (sausage.Weight > weight)
                            {
                                newSausage      = new Sausage(sausageType, sausage.DateOfExpiry, weight);
                                sausage.Weight -= weight;
                                weight          = 0.0;
                                isFirstSausage  = false;
                            }
                            else
                            {
                                newSausage     = new Sausage(sausageType, sausage.DateOfExpiry, sausage.Weight);
                                weight        -= sausage.Weight;
                                sausage.Weight = 0.0;
                                isFirstSausage = false;
                            }
                            break;
                        }
                    }
                    if (isFirstSausage)
                    {
                        break;
                    }
                }
                else
                {
                    foreach (Sausage sausage in _listOfSausages)
                    {
                        if (weight <= 0.001)
                        {
                            break;
                        }
                        if (sausage.SausageType == sausageType)
                        {
                            if (sausage.Weight > weight)
                            {
                                newSausage.Weight += weight;
                                sausage.Weight    -= weight;
                                weight             = 0.0;
                            }
                            else
                            {
                                newSausage.Weight += sausage.Weight;
                                weight            -= sausage.Weight;
                                sausage.Weight     = 0.0;
                            }
                        }
                    }
                    break;
                }
                for (int i = _listOfSausages.Count - 1; i >= 0; i--)
                {
                    if (_listOfSausages[i].Weight <= 0.001)
                    {
                        _listOfSausages.RemoveAt(i);
                    }
                }
            } while (weight > 0.001);

            return(newSausage);
        }