i manage to build the code but i'm not sure its correct.
additionaly there is only 1 random function that is been used for
all,its wrong of couse


        interface IFoo
        {
                void foo(int a,int b);
        }
        class Factory:IFoo
        {
                int _a,_b;
                public virtual void foo(int a,int b)
                {
                        Random _randomizer;
                        _randomizer = new Random();
             this._a = a;
             this._b = b;
        if(_randomizer.Next() % 4 == 0)
                plus();
            else if(_randomizer.Next() % 4 == 1)
                   minus();
            else if(_randomizer.Next() % 4 == 2)
                  dividor();
        else multiplier();
                }
                public void plus()
                {
         Console.WriteLine("{0}+{1}={2}",_a,_b,_a+_b);
                }
                public void minus()
                {
         Console.WriteLine("{0}-{1}={2}",_a,_b,_a-_b);
                }
                public void dividor()
                {
         Console.WriteLine("{0}/{1}={2}",_a,_b,_a/_b);
                }
                public void multiplier()
                {
         Console.WriteLine("{0}*{1}={2}",_a,_b,_a*_b);
                }
        }
        class MainClass
        {
                static void Main(string[] args)
                {
            IFoo[] df = new IFoo[10];
                        for(int i=0;i<10;i++)
                        {
             df[i] = new Factory();
                         df[i].foo(i+1,i+1);
                        }
                }
        }
On 21 יוני, 10:03, Cerebrus <[email protected]> wrote:
> I think this should be pretty straightforward... Show us your efforts
> in this direction... what code have you written so far ?
>
> On Jun 21, 12:01 am, thread <[email protected]> wrote:
>
>
>
> > hi,
> > I'm trying to implement some exercise but its not going that easy:
> > I need to define interface called IF00 that includes a method called
> > foo that gets 2 ints and returning their function.
> > I need to implement 4 implementation of the
> > interface:multiplier,divider,plus and minus.
> > I need to create a class called Factory that returning randomly Ifoo
> > type.
> > the Main method should be using only the Factory class and the Ifoo
> > interface for randomizing the function 10 times and activate it on the
> > couple 1,1,2,2,3,3...10,10
>
> > any idea?-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-

Reply via email to