Exemplo n.º 1
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
        }
Exemplo n.º 2
0
        //assume you know how to obtain user entered data
        static void Main(string[] args)
        {
            double height = 6.5, width = 8.0, linearLength = 135.0, price = 108.00;
            string style = "Neighbour Friendly: Spruce";

            //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);

            //obtain and store gate data
            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 Friendly 1/2 Picket: Spruce";
            price    = 86.45;

            //name of the instance  the dot 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 dot operator  the Behavior name
            theEstimate.CalculatePrice();

            //client wishes a 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();
            }
            Console.WriteLine(string.Format("total fence surface area {0:0.00}", fenceArea * 2));


            Console.ReadKey();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 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
Exemplo n.º 5
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
        }