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