Code Explanation

I'm getting a little lost. I was wondering if someone can give me line by line explanation of the code bellow.


  class Pineapple
    {
        const string d = @"c:\chow\deliveryg.txt";
        public enum Fargo { North, South, East, West, Flamingo }
        public static void Main()
        {
            StreamWriter o = new StreamWriter(@"c:\chow\orderg.txt");
            Pizza pz = new Pizza(new StreamWriter(d, true));
            pz.Idaho(Fargo.Flamingo);
            for (int w = 3; w >= 0; w--)
            {
                Pizza i = new Pizza(new StreamWriter(d, false));
                i.Idaho((Fargo)w);
                Party p = new Party(new StreamReader(d));
                p.HowMuch(o);
            }
            o.WriteLine("That’s all folks!");
            o.Close();
        }
    }

    class Pizza
    {
        private StreamWriter writer;
        public Pizza(StreamWriter writer)
        {
            this.writer = writer;
        }
        public void Idaho(Pineapple.Fargo f)
        {
            writer.WriteLine(f);
            writer.Close();
        }
    }

    class Party
    {
        private StreamReader reader;
        public Party(StreamReader reader)
        {
            this.reader = reader;
        }
        public void HowMuch(StreamWriter q)
        {
            q.WriteLine(reader.ReadLine());
            reader.Close();
        }
    }

Open in new window

yguyon28Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

piattndCommented:
I'm looking through it right now, but where did you get this code?  At first glance it looks really confusing for what it actually does....
0
plusone3055Commented:
it looks like its writing the pizza order to a text file (most likely printing a receipt for the order)
0
plusone3055Commented:
piattnd:
I think we can agree there is some more code to this snippet that is missing

why this class was named Pinapple is a little mystery to me becuase it looks like the enum is coming up with street names

Strange indeed :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
piattndCommented:
Because I have very limited knowledge of HOW this code is used, this is the best I could do for interpreting it.


class Pineapple
    {
        //set d to the path of a target text file
        const string d = @"c:\chow\deliveryg.txt";

        //establish an enumeration with values.  This will be called later by typing Fargo.Item
        public enum Fargo { North, South, East, West, Flamingo }

        //This is your main method of the pineapple class
        public static void Main()
        {
            //open a stream writer so you can write to the text file shown in the ""s
            StreamWriter o = new StreamWriter(@"c:\chow\orderg.txt");

            //Initiate a new instance of the Pizza class.  The pizza class requires a StreamWriter, so you pass it a new instance of a stream writer
            //You pass in the path stored in string 'd' and say true to inidicate overwriting is enabled.
            Pizza pz = new Pizza(new StreamWriter(d, true));

            //You call the Idaho method and pass the Fargo.Flamingo as the parameter.  You can see the Idaho method requires a Pineapple.Fargo reference when you call it.
            //Calling pz.Idaho will result in writing the value of the enum object Fargo.Flamingo to a text file established in your pz instance creation above
            pz.Idaho(Fargo.Flamingo);

            //Set w to a value of 3 and run through this code until w = 0.  Each time it runs through the code, w will be subtracted by 1, so it should run 3 times.
            for (int w = 3; w >= 0; w--)
            {
                //Initiate a new instance of the Pizza class and use the same path as before to write to, but disable overwriting.
                Pizza i = new Pizza(new StreamWriter(d, false));
                //Call the Idaho method inside the pizza class again and pass the Pineapple.Fargo value at a particular location using the number value of w.
                //I would assume the first pass through would use "west", the second would use "east" and third "south".
                i.Idaho((Fargo)w);
                //Initiate a new instance of the Party class and pass it a stream reader to read the file established in d.
                Party p = new Party(new StreamReader(d));
                //Execute the HowMuch method, which requires a stream writer.  You pass in streamwriter o that writes to the c:\chow\orderg.txt file.
                p.HowMuch(o);
            }
            //write this text to the C:\chow\orderg.txt file and close the file.
            o.WriteLine("That’s all folks!");
            o.Close();
        }
    }

    class Pizza
    {
        //establish writer as a streamwriter type for later use
        private StreamWriter writer;

        //Associate the writer with the Pizza class you initialize
        public Pizza(StreamWriter writer)
        {
            this.writer = writer;
        }

        //Idaho method that expects a Pineapple.Fargo (enumeration) and writes to the file as indicated when you initiated the Pizza class.  Closes the file.
        public void Idaho(Pineapple.Fargo f)
        {
            writer.WriteLine(f);
            writer.Close();
        }
    }

    class Party
    {
        //establish reader as a streamreader for later use   
        private StreamReader reader;

        //Associate the reader with the Party class you initialize
        public Party(StreamReader reader)
        {
            this.reader = reader;
        }

        //HowMuch method which expects a StreamWriter to be passed to it when you call it.
        public void HowMuch(StreamWriter q)
        {
            //write the value that was inside of the line read in the reader to the file designated in the call to this method and close the reader file.
            q.WriteLine(reader.ReadLine());
            reader.Close();
        }
    } 

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.