Пример #1
0
        //assuming you kno whow to obtain user entered data
        static void Main(string[] args)
        {
            double height        = 6.5;
            double width         = 8.0;
            double linerarlength = 135.0;
            string style         = "neighboor fiendly: spruce";
            double price         = 108.00;

            //store panel data
            //declare storage area for fence data

            //create a non static instace of a class
            //use the new command to create the class instance
            // the new command refererences the class constructor
            FencePanel panelInfo = new FencePanel(height, width, style, price); //greedy

            //obtain and store gate data
            FenceGate        gateInfo;
            List <FenceGate> gateList = new List <FenceGate>();

            //Assume looping to obtain all gate data
            //each loop is one gate
            //pass 1
            height   = 6.25;
            width    = 4.0;
            style    = "Neighboor friendly 1/2 picket : spruce";
            price    = 86.45;
            gateInfo = new FenceGate(); //default constructor OR system constructor

            //name of the instance followed by the dot opperator then is followed by the property name
            gateInfo.GateHeight = height; //set of the property
            gateInfo.GatePrice  = price;
            gateInfo.GateStyle  = style;
            gateInfo.GateWidth  = width;
            gateList.Add(gateInfo);

            //Pass 2
            height   = 6.25;
            width    = 3.0;
            style    = "Neighboor friendly: spruce";
            price    = 72.95;
            gateInfo = new FenceGate(height, width, style, price);
            gateList.Add(gateInfo);

            //assume end of looping

            //create estimate
            Estimate theEstimate = new Estimate();

            theEstimate.LinearLength = linerarlength;
            theEstimate.Panel        = panelInfo;
            theEstimate.Gates        = gateList;
            theEstimate.CalculateTotalPrice();

            //client wishes a output of the estimate
            Console.WriteLine("the fence is to be a " + theEstimate.Panel.Style + " style");
            Console.WriteLine("The total cost of the estimate is {0:0.00}", theEstimate.TotalPrice); //get
            Console.WriteLine("Number of requred panels is {0}", theEstimate.Panel.EstimatedNumberOfPanels(theEstimate.LinearLength));
            Console.WriteLine("The number of gates is {0}", theEstimate.Gates.Count);
            double fenceArea = theEstimate.Panel.TotalArea(theEstimate.LinearLength);

            foreach (var item in theEstimate.Gates)
            {
                fenceArea += item.GateArea(); //item represents a single Gate instance in the colection
            }
            Console.WriteLine(string.Format("Total fence surface area {0:0.0}", fenceArea * 2));

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            //assume that you know how to do data input into
            //  a console application (CPSC1012)
            //the input data will simply be placed in a local variable
            //linearlength
            double linearlength = 135.0;
            //height
            double height = 6.5;
            //width
            double width = 8.0;
            //style
            string style = "Neighbour friendly: Spruce";
            //price
            double price = 108.00;


            //situation: have the required data fro the class instance
            //options a) create instance using default constructor AND
            //           multiple assignment statements
            //        b) create instance using the greedy constructor
            //solution: b) one statement

            //FencePanel is a non-static class
            //Console was a static class (DOES NOT store data)
            //for a non-static class, you MUST create an instance of the class
            //      to be able to use the class
            //syntax using the new keyword which requires a reference to the
            //      appropriate class constructor
            FencePanel panel = new FencePanel(height, width, style, price);

            //handle numerious gates
            //craete a class pointer able to reference the Gare class
            //this pointer will be null
            Gate gateinfo;

            //a structure tohold a collection of Gate
            //the structure to use should hold an unknown number of instances
            //structure will be a List<T>
            //create the new instance of the List<T> when it is defined
            List <Gate> gatelist = new List <Gate>();

            //assume you are in a loop to gather multiple gates


            //1st gate:
            //technique 1
            //create instance of Gate
            //collect data
            //add to List
            gateinfo = new Gate();
            height   = 6.25;
            width    = 4.0;
            style    = "Neighbour friendly - 1/2 picket: spruce";
            price    = 86.45;

            gateinfo.Height = height;
            gateinfo.Width  = width;
            gateinfo.Style  = style;
            gateinfo.Price  = price;
            gatelist.Add(gateinfo);


            //2nd gate:
            //technique 2
            //collect the data
            //create the Gate instance
            //add to list

            height   = 6.25;
            width    = 3.0;
            style    = "Neighbour friednly: spruce";
            price    = 72.45;
            gateinfo = new Gate(height, width, style, price);
            gatelist.Add(gateinfo);


            //create the Estimate
            Estimate ClientEstimate = new Estimate(); //system default

            ClientEstimate.LinearLength = linearlength;
            ClientEstimate.Panel        = panel;
            ClientEstimate.Gates        = gatelist;
            ClientEstimate.CalculatePrice();

            //output client information
            Console.WriteLine("The fence is to be a " + ClientEstimate.Panel.Style + " style");
            Console.WriteLine("The linear fence length required is {0:0.0}", ClientEstimate.LinearLength);
            Console.WriteLine("Number of required panels {0}",
                              ClientEstimate.Panel.EstimatedNumberOfPanels(ClientEstimate.LinearLength));
            Console.WriteLine("Number of required gates {0}", ClientEstimate.Gates.Count);
            double fenceArea = ClientEstimate.Panel.FenceArea(ClientEstimate.LinearLength);

            foreach (var item in ClientEstimate.Gates)
            {
                fenceArea += item.GateArea();
            }
            Console.WriteLine(string.Format("Total fence surface area {0:0.00}", fenceArea * 2));
            Console.ReadKey();  //required due to using just F5
        }
Пример #3
0
        //assume you know how to obtain user entered data
        static void Main(string[] args)
        {
            double height = 6.5;
            double width = 8.0;
            double linearlength = 135.0;
            string style = "Neighbour Friendly: Spruce";
            double price = 108.00;

            //store the fence data
            // declare a storage area for the fence data

            //create a non-static instance of a class
            //use the new command to create the class instance
            //the new command references the class constructor
            FencePanel fenceInfo = new FencePanel(height, width, style, price); //greedie

            //obtain and store gate info
            Gate gateinfo;
            List<Gate> gatelist = new List<Gate>();

            //assume looping to obtain all gate data
            //each loop is one gate
            //pass 1
            gateinfo = new Gate(); //system constructor since Gate has NO constructors
            height = 6.25;
            width = 4.0;
            style = "Neighbour Frienly 1/2 Picket: Spruce";
            price = 86.45;
            gateinfo.Height = height;
            gateinfo.Width = width;
            gateinfo.Style = style;
            gateinfo.Price = price;
            gatelist.Add(gateinfo);

            //pass 2
            gateinfo = new Gate(); //system constructor since Gate has NO constructors
            height = 6.25;
            width = 3.25;
            style = "Neighbour Frienly: Spruce";
            price = 86.45;
            gateinfo.Height = height;
            gateinfo.Width = width;
            gateinfo.Style = style;
            gateinfo.Price = price;
            gatelist.Add(gateinfo);

            //assume end of gate looping

            //create the Estimate
            Estimate theEstimate = new Estimate() //class default constructor
            theEstimate.LinearLenght = linearlength;
            theEstimate.Panel = fenceInfo;
            theEstimate.Gates = gatelist;
            theEstimate.CalculatePrice();


            //client wishes an output of the estimate
            Console.WriteLine("The fence is to be a " + theEstimate.Panel.Style + " style");
            Console.WriteLine("Total linear length requested {0}", theEstimate.LinearLength);
            Console.WriteLine("Number of required panels: {0}"), theEstimate.Panel.EstimatedNumberOfPanels(theEstimate.LinearLength));
            Console.WriteLine("Number of gates: {0}"), theEstimate.Gates.Count);
            double fenceArea = theEstimate.Panel.FenceArea(theEstimate.LinearLength);
            foreach(var item in theEstimate.Gates)
            {
                fenceArea += item.GateArea();
            }
        }
Пример #4
0
        //assume you now how to obtain user entered data
        static void Main(string[] args)
        {
            double height       = 6.5;
            double width        = 8.0;
            double linearlength = 135.0;
            string style        = "Neighbour Friendly: Spruce";
            double price        = 108.00;

            //Store fence area
            //declare storage area for the fence data

            //create a "static" instance of a class
            //      (static doesn't change)
            //use the "new" command reference the class constructor

            Fence_Panel fenceInfo = new Fence_Panel(height, width, style, price); //order matters

            //obtain and store gate data
            Gate        gateInfo;
            List <Gate> gatelist = new List <Gate>();

            //assuming looping to optain all gate data
            //each loop is one gate

            //Pass #1
            gateInfo = new Gate(); //system constructor since Gate has NO constructors
            height   = 6.25;
            width    = 4.0;
            style    = "Neighbour Friendly 1/2 Picket: Spruce";
            price    = 86.45;

            //name of the instance, the "." operator, the Property name = value;
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;
            gatelist.Add(gateInfo);

            //Pass #2
            gateInfo        = new Gate(); //system constructor since Gate has NO constructors
            height          = 6.25;
            width           = 3.25;
            style           = "Neighbour Friendly: Spruce";
            price           = 86.45;
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;
            gatelist.Add(gateInfo);

            //Assume end of gate looping

            //create the Estimate
            Estimate theEstimate = new Estimate();//class default constructor

            theEstimate.LinearLength = linearlength;
            theEstimate.Panel        = fenceInfo;
            theEstimate.Gates        = gatelist;

            //name of the instance the "." operator, the behaviour name
            theEstimate.CalculatePrice();

            //client desires the output of the estimate
            Console.WriteLine("The fence is to be a " + theEstimate.Panel.Style + " style");
            //dot operator (".") is like file explorer
            Console.WriteLine("\nTotal linear length requested: {0} ", theEstimate.LinearLength);
            Console.WriteLine("Number of required panels: {0} ",
                              theEstimate.Panel.EstimatedNumberOfPanels(theEstimate.LinearLength));
            Console.WriteLine("Number of gates: {0}", theEstimate.Gates.Count);
            double fenceArea = theEstimate.Panel.FenceArea(theEstimate.LinearLength);

            foreach (var item in theEstimate.Gates)
            {
                fenceArea += item.GateArea();
            }//OFFE
            Console.WriteLine(string.Format("\nTotal fence surface area {0:0.00}", fenceArea * 2));

            Console.ReadLine();
        } //eom
Пример #5
0
        static void Main(string[] args)
        {
            double height       = 6.5;
            double width        = 8.0;
            double linearheight = 125.0;
            string style        = "Neighbour Friendly";
            double price        = 296.80;

            //creae a non-statice instance of a class
            //the new command reference the class constructor

            FencePanel fenceinfo = new FencePanel(height, width, style, price);


            Gate        gateInfo;
            List <Gate> gateList = new List <Gate>();

            gateInfo        = new Gate();
            height          = 6.25;
            width           = 4.0;
            style           = "neighbour Friendly - Picket";
            price           = 325.0;
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;
            gateList.Add(gateInfo);

            //pass 2
            gateInfo        = new Gate();
            height          = 6.25;
            width           = 4.0;
            style           = "neighbour Friendly - Spruce";
            price           = 325.0;
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;
            gateList.Add(gateInfo);

            //create the estimate
            Estimate theestimate = new Estimate();      //class default costructor

            theestimate.LinearLength = linearheight;
            theestimate.Panel        = fenceinfo;
            theestimate.Gates        = gateList;
            theestimate.CalculatePrice();

            Console.WriteLine("The Fence is to be a" + theestimate.Panel.Style);
            Console.WriteLine("Total Linear Length {0}", theestimate.LinearLength);
            Console.WriteLine("Number of Required panels{0}", theestimate.Panel.EstimatedNumberOfPanels(theestimate.LinearLength));
            Console.WriteLine("Number of Gates{0}", theestimate.Gates.Count);

            double fencearea = theestimate.Panel.FenceArea(theestimate.LinearLength);

            foreach (var item in theestimate.Gates)
            {
                fencearea += item.GateArea();
            }

            Console.WriteLine(string.Format("The total Fence Area is{0}", fencearea * 2));
            Console.ReadKey();
        }
Пример #6
0
        static void Main(string[] args)
        {
            //assume that you know how to do the data input into a console application
            //the input data will simply be placed in a local variable
            //linear length
            double linearlength = 135.0;
            //height
            double height = 6.5;
            //width
            double width = 8.0;
            //style
            string style = "Neighbour friendly: Spruce";
            //price
            double price = 108.00;

            //situation: have the required data for the class instance
            //options
            //  a) create instance default constructor AND multiple assignment statements
            //  b) create instance using the greedy constructor
            //Solution: b) one statement

            //FencePanel is a non-static class that must be declared
            //Console was a static class (DOES NOT store data)
            //For a non-static class you MUST create an instance of the class to be able to use it.
            //Syntax using the new keyword which requires a reference to the appropriate class constructor
            FencePanel Panel = new FencePanel(height, width, style, price);

            //handle numerous gates
            //create a class pointer able to reference the Gate class. it will be null be default and doesn't have to be declared as such.
            Gate GateInfo; //like a parking space waiting for cars

            //a structure to hold a collection of Gate
            //the structure to use should hold an unknown number of instances. it will be a List<T> (T represents the datatype)
            //Create the new instance of the List<T> when it is defined.
            List <Gate> gatelist = new List <Gate>();

            //assume you are in a loop to gather multiple gates

            //technique 1
            //create instance of Gate
            //collect data
            //add to List
            GateInfo        = new Gate(); //start off with the default constructor until you insert information
            height          = 6.25;
            width           = 4.0;
            style           = "Neighbour friendly - 1/2 picket: spruce";
            price           = 86.45;
            GateInfo.Height = height;
            GateInfo.Width  = width;
            GateInfo.Style  = style;
            GateInfo.Price  = price;
            gatelist.Add(GateInfo);
            //not efficient as a default constructor as such. using a greedy constructor is best.

            //technique 2
            //collect data
            //create instance of Gate
            //add to the list
            height   = 6.25;
            width    = 3.0;
            style    = "Neighbour friendly: spruce";
            price    = 72.45;
            GateInfo = new Gate(height, width, style, price); //greedy constructor
            gatelist.Add(GateInfo);

            //create the Estimate
            //Estimate ClientEstimate = new Estimate(linearlength, panel, gates); this is not possible as the constructor was not declared in the Estimate Class
            Estimate ClientEstimate = new Estimate();

            ClientEstimate.LinearLength = linearlength; //linear length is a property of a class. the assignment rules to not change
            ClientEstimate.TotalPanels  = Panel;
            ClientEstimate.TotalGates   = gatelist;
            //ClientEstimate.TotalPrice = 450.98; this cannot be done as the price is private. instead you muse use the public double
            ClientEstimate.CalculateTotalPrice();

            //nothing should be stored in a static class, only behaviours
            Console.WriteLine("The fence is to be a " + ClientEstimate.TotalPanels.Style + "style");            ///Class.Property.PropertyInstance/Behaviour
            Console.WriteLine("The linear fence length is {0:0.0}", ClientEstimate.LinearLength);               //Placeholder concatenation
            Console.WriteLine("Number of required panels is {0}",
                              ClientEstimate.TotalPanels.EstimatedNumberOfPanels(ClientEstimate.LinearLength)); //Class.Property.Method(Parameters)
            Console.WriteLine("Number of required gates {0}",
                              ClientEstimate.TotalGates.Count);
            double fencearea = ClientEstimate.TotalPanels.FenceArea(ClientEstimate.LinearLength);

            foreach (var item in ClientEstimate.TotalGates)
            {
                fencearea += item.GateArea();
            }
            Console.WriteLine(string.Format("Total Fence Surface Area: {0:0.00}", fencearea * 2)); //2 sides of the fence
            Console.ReadKey();                                                                     //required due to using just f5
        }
Пример #7
0
        //assume you know how to obtain user entered data
        static void Main(string[] args)
        {
            double height       = 6.5;
            double width        = 8.0;
            double linearlength = 135.0;
            string style        = "Neighbour Friendly: Spruce";
            double price        = 108.00;

            //store the fence area
            //declare a storage area for the fence data

            //create a non-static instance of a class
            //use the new command to create the class instance
            //the new command references the class constructor
            FencePanel fenceinfo = new FencePanel(height, width, style, price);

            //obtain and store gate data
            FenceGate        gateInfo;
            List <FenceGate> gateList = new List <FenceGate>();

            //assume looping to obtain all gate data
            //each loop is one gate
            //pass 1
            gateInfo        = new FenceGate(); //system constructor since Gate has no constructors
            height          = 6.25;
            width           = 4.0;
            style           = "Neighbour Friendly 1/2 Picket: Spruce";
            price           = 86.45;
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;
            gateList.Add(gateInfo);

            //pass 2
            gateInfo = new FenceGate(); //system constructor since Gate has no constructors
            height   = 6.25;
            width    = 4.0;
            style    = "Neighbour Friendly: Spruce";
            price    = 86.45;
            //name of the instance, the dotoperator (the period), the property = value
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;
            gateList.Add(gateInfo);

            //assume end of gate looping

            //create the estimate
            Estimate theEstimate = new Estimate(); //class default constructor

            theEstimate.LinearLength = linearlength;
            theEstimate.Panel        = fenceinfo;
            theEstimate.Gates        = gateList;

            //name of the instance, the . and the behavior(method) name
            theEstimate.CalculatePrice();

            //client wishes a output of the estimate
            //both ways below is correct, just depends which one you want
            Console.WriteLine("The fence is to be a " + theEstimate.Panel.Style + " style");
            Console.WriteLine("Total linear length requested {0}", theEstimate.LinearLength);
            Console.WriteLine("Number of required panels: {0}", theEstimate.Panel.EstimatedNumberOfPanels(linearlength));
            //.count lets you count the number of instances inside Gates
            Console.WriteLine("Number of gates: {0}", theEstimate.Gates.Count);
            double fenceArea = theEstimate.Panel.FenceArea(theEstimate.LinearLength);

            foreach (var item in theEstimate.Gates)
            {
                fenceArea += item.GateArea();
            }
            Console.WriteLine(string.Format("total fence surface area {0:0.00}", fenceArea * 2));
            Console.ReadKey();
        }
Пример #8
0
        // assume you know how to obtain user entered data
        static void Main(string[] args)
        {
            double height       = 6.5;
            double width        = 8.0;
            double linearLength = 135.0;
            string style        = "Neightbour friendly: Spruce";
            double price        = 108.00;

            // store the fence data
            // declare a storage area

            // create a non static instance of a class
            // use the new command to create the class instance
            // the new command references the class constructor

            FencePanel fenceInfo = new FencePanel(height, width, style, price);

            // obtain and store gate data
            FenceGate        gateInfo;
            List <FenceGate> gateList = new List <FenceGate>();

            // assuming looping to obtrain all gate data
            // each loop is one gate
            // Pass 1
            gateInfo        = new FenceGate(); // system constructor since FenceGate has no constructors
            height          = 6.25;
            width           = 4.0;
            style           = "Neightbour Freindly 1/2 Picket: Spruce";
            price           = 86.45;
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;

            // Pass 2

            gateInfo = new FenceGate(); // system constructor since FenceGate has no constructors
            height   = 6.25;
            width    = 4.0;
            style    = "Neightbour Freindly: Spruce";
            price    = 86.45;

            // name of the instance dot operator the property name = value
            gateInfo.Height = height;
            gateInfo.Width  = width;
            gateInfo.Style  = style;
            gateInfo.Price  = price;

            //assume end of looping

            // create the estimate
            Estimate theEstimate = new Estimate(); // class default constructor

            theEstimate.LinearLength = linearLength;
            theEstimate.Panel        = fenceInfo;
            theEstimate.Gates        = gateList;

            //name of the instance dot operator behaviour name
            theEstimate.CalculatePrice();

            Console.WriteLine("The fence is to be a " + theEstimate.Panel.Style + " style");
            Console.WriteLine("Total Linear length requested {0}", theEstimate.LinearLength);
            Console.WriteLine("Total Linear length requested {0}",
                              theEstimate.Panel.EstimatedNumberOfPanels(theEstimate.LinearLength));
            Console.WriteLine("Number of gates: {0}", theEstimate.Gates.Count);
            double fenceArea = theEstimate.Panel.FenceArea(theEstimate.LinearLength);

            foreach (var item in theEstimate.Gates)
            {
                fenceArea += item.GateArea();
            }
            Console.WriteLine(string.Format("Total fence surface are{0:0.00}", fenceArea * 2));
        }