private void cBoxMaterial_SelectedIndexChanged(object sender, EventArgs e) { string material = cBoxMaterial.SelectedItem.ToString(); double density; bool canModified = false; switch (material) { case "鋁": _mType = ShapeType.Material.Al; density = 2.7; break; case "鐵": _mType = ShapeType.Material.Fe; density = 7.87; break; case "鉛": _mType = ShapeType.Material.Pb; density = 11.3; break; default: _mType = ShapeType.Material.UNKNOW; density = 0; canModified = true; break; } txtDensity.Text = density.ToString(); if (!canModified) { txtDensity.Enabled = false; } }
public Pyramid(double side, double height, ShapeType.Material mType) : base(mType) { _geo = ShapeType.Geo.PYRAMID; Side = side; Height = height; _amount++; }
public Cylinder(double radius, double height, ShapeType.Material mType) : base(mType) { _geoType = ShapeType.Geo.CYLINDER; Radius = radius; Height = height; _amount++; }
public static Shape3D Create(string name, ShapeType.Material mType, double arg1, double arg2) { Shape3D rv = null; switch (name) { case "球": rv = Ball.Create(arg1, mType); return(rv); case "立方體": rv = Cube.Create(arg1, mType); return(rv); case "圓柱體": rv = Cylinder.Create(arg1, arg2, mType); return(rv); case "金字塔": rv = Pyramid.Create(arg1, arg2, mType); return(rv); default: return(rv); } }
public static string Name(ShapeType.Material mType) { foreach (var e in elements) { if (e.MaterialType == mType) { return(e.Name); } } return("未知"); }
public static Cube Create(double side, ShapeType.Material mType) { if (side <= 0) { throw new NegativeException("邊長不可小於或等於零!"); } else { return(new Cube(side, mType)); } }
public static double Density(ShapeType.Material mType) { foreach (var e in elements) { if (e.MaterialType == mType) { return(e.Density); } } return(0); }
// private static double _pi=3.1415926; //可以使用 readonly 來修飾 public static Ball Create(double radius, ShapeType.Material mType) { if (radius <= 0) { throw new NegativeException("半徑不可小於或等於零!"); } else { return(new Ball(radius, mType)); } }
//private static double _pi = 3.1415926; public static Cylinder Create(double radius, double height, ShapeType.Material mType) { if (radius <= 0) { throw new NegativeException("半徑不可小於或等於零!"); } else if (height <= 0) { throw new NegativeException("高度不可小於或等於零!"); } else { return(new Cylinder(radius, height, mType)); } }
protected ShapeType.Material _materialType; //_material 與 _density 有相關性 public Shape3D() { _materialType = ShapeType.Material.UNKNOWN; _amount++; }
public Ball(double radius, ShapeType.Material mType) : base(mType) { _geoType = ShapeType.Geo.BALL; Radius = radius; _amount++; }
public Cube(double side, ShapeType.Material mType) : base(mType) { _geoType = ShapeType.Geo.CUBE; Side = side; _amount++; }
public Shape3D(ShapeType.Material mType) { //Density = density; _material = mType; _amount++; }
public Shape3D() { //_density = 0; _material = ShapeType.Material.UNKNOW; _amount++; }
private void setMaterialProperties(object sender, SetMaterialEventArgs e) { _mType = e.MType; txtMaterial.Text = MaterialTable.Name(e.MType); txtDensity.Text = MaterialTable.Density(e.MType).ToString(); }
public void MaterialFunc(object sender, MaterialEventArgs e) { _mType = e.MaterialType; txtMaterial.Text = e.MaterialName; txtDensity.Text = MaterialTable.Density(e.MaterialType).ToString(); }
public Shape3D(ShapeType.Material mType) { _materialType = mType; _amount++; }
public Element(ShapeType.Material mType, string name, double density) { MaterialType = mType; Name = name; Density = density; }