// method to display a Circle object private void Display(Circle c) { ListViewItem lvi = null; if (c is Cone) { // cast C to a cone object Cone co = (Cone)c; // create a listviewItem (one row in a listview) string[] items = { co.GetType().Name, co.Radius.ToString("f3"), co.Height.ToString("f3"), co.Perimeter().ToString("f3"), co.Area().ToString("f3"), co.Volume().ToString("f3") }; lvi = new ListViewItem(items); } else if (c is Cylinder) { // cast C to a cylinder object Cylinder cy = (Cylinder)c; // create a listviewItem (one row in a listview) string[] items = { cy.GetType().Name, cy.Radius.ToString("f3"), cy.Height.ToString("f3"), cy.Perimeter().ToString("f3"), cy.Area().ToString("f3"), cy.Volume().ToString("f3") }; lvi = new ListViewItem(items); } else if (c is Sphere) { // castc to a Sphere object Sphere sp = (Sphere)c; // create a listviewItem string[] items = { sp.GetType().Name, sp.Radius.ToString("f3"), "0", sp.Perimeter().ToString("f3"), sp.Area().ToString("f3"), sp.Volume().ToString("f3") }; lvi = new ListViewItem(items); } else { // create a listviewItem (one row in a listview) string[] items = { c.GetType().Name, c.Radius.ToString("f3"), "0", c.Perimeter().ToString("f3"), c.Area().ToString("f3"), c.Volume().ToString("f3") }; lvi = new ListViewItem(items); } // add the row to the listview listView1.Items.Add(lvi); // making the last item visible listView1.EnsureVisible(listView1.Items.Count - 1); }
/// <summary> /// If a shape have been selected, ask for information for it and gather it. Make it sound better /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AreaVariableConfirm_Click(object sender, RoutedEventArgs e) { if (circleBool) { if (areaState == 0) { AreaTextBox.Text = "Radius"; areaState++; } else if (areaState == 1) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { circle.Area((float)num); circle.VisualRepresentation(); AreaTextBox.Text = "Correct shape?"; AreaBoolChanger(false, false, false, false); areaState = 0; } } } else if (trapezoidBool) { if (areaState == 0) { AreaTextBox.Text = "Height"; areaState++; } else if (areaState == 1) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { trapezoidArray[0] = (float)num; AreaTextBox.Text = "First length"; areaState++; } } else if (areaState == 2) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { trapezoidArray[1] = (float)num; AreaTextBox.Text = "Second length"; areaState++; } } else if (areaState == 3) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { trapezoidArray[2] = (float)num; trapezoid.Area(trapezoidArray[0], trapezoidArray[1], trapezoidArray[2]); trapezoid.VisualArrayCalculation(); trapezoid.VisualRepresentation(); AreaTextBox.Text = "Correct shape?"; AreaBoolChanger(false, false, false, false); areaState = 0; } } } else if (coneBool) { if (areaState == 0) { AreaTextBox.Text = "Radius"; areaState++; } else if (areaState == 1) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { coneArray[0] = (float)num; AreaTextBox.Text = "Height"; areaState++; } } else if (areaState == 2) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { coneArray[1] = (float)num; cone.Area(coneArray[0], coneArray[1]); cone.VisualArrayCalculation(); cone.VisualRepresentation(); AreaTextBox.Text = "Correct shape?"; AreaBoolChanger(false, false, false, false); areaState = 0; } } } else if (polygonBool) { if (areaState == 0) { AreaTextBox.Text = "Length"; areaState++; } else if (areaState == 1) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { polygonLength = (float)num; AreaTextBox.Text = "Amount of sides"; areaState++; } } else if (areaState == 2) { string valueTxt = AreaTextBox.Text; bool gotNumber = GetNumber(valueTxt, out float?num); if (gotNumber) { polygonSideAmount = (uint)num; polygon.Area(polygonSideAmount, polygonLength); polygon.VisualArrayCalculation(); polygon.VisualRepresentation(); AreaTextBox.Text = "Correct shape?"; AreaBoolChanger(false, false, false, false); areaState = 0; } } } }