public void Area_should_be_side_length_times_two() { var square = new Square {SideLength = 5}; var area = square.GetArea(); Assert.AreEqual(25, area); }
static void Main() { //creates a Triangle and calculates surface var triangle = new Triangle(3.2, 4.5); var triangleSurface = triangle.CalculateSurface(); //creates a Rectangle and calculates surface var rectangle = new Rectangle(4, 12.3); var rectangleSurface = rectangle.CalculateSurface(); //creates a Square and calculates surface var square = new Square(5); var squareSurface = square.CalculateSurface(); //prints shapes and surfaces PrintShape(triangle); Console.WriteLine("Surface of the triangle is: {0}", triangleSurface); Console.WriteLine(new string('-', 30)); Console.WriteLine(); PrintShape(rectangle); Console.WriteLine("Surface of the rectangle is: {0}", rectangleSurface); Console.WriteLine(new string('-', 30)); Console.WriteLine(); PrintShape(square); Console.WriteLine("Surface of the square is: {0}", squareSurface); Console.WriteLine(new string('-', 30)); }
public void Run() { var shapeAreaPrinter = new ShapeAreaPrinter(); var square = new Square {SideLength = 5}; shapeAreaPrinter.PrintShapeArea(square); }
public virtual bool Equals(Square square) { if (square == null || GetType() != square.GetType()) return false; else if (Type == square.Type && _side == square._side) return true; else return false; }
static void Main(string[] args) { Rectangle rectangle = new Rectangle(5, 6); rectangle.CalculateSruface(); Triangle triangle = new Triangle(4, 3); triangle.CalculateSruface(); Square square = new Square(7, 7); square.CalculateSruface(); }
public void DefaultSquareContructorCanComputeArea() { var square = new Square(); square.Top = 5; square.Right = 5; square.Bottom = 5; square.Left = 5; Assert.AreEqual(square.Area(), 25); }
static void Main() { var triangle = new Triangle(4, 3); var rectangle = new Rectangle(12, 10); var square = new Square(10); Console.WriteLine("The Area of Triangle is: {0}", triangle.CalculateSurface()); Console.WriteLine("The Area of Rectangle is: {0}", rectangle.CalculateSurface()); Console.WriteLine("The Area of Square is: {0}", square.CalculateSurface()); }
static void Main() { var rect = new Rectangle(12, 32.21); var square = new Square(12, 12); var tri = new Triangle(33, 12); Console.WriteLine(rect.CalculateSurface()); Console.WriteLine(square.CalculateSurface()); Console.WriteLine(tri.CalculateSurface()); var squareCheck = new Square(12, 13); }
static void Main() { var shapes = new Shape[3]; shapes[0] = new Rectangle(3, 4); shapes[1] = new Triangle(3, 4); shapes[2] = new Square(3); foreach (var shape in shapes) { Console.WriteLine(shape.CalculateSurface()); } }
static void Main() { List<Shape> shape = new List<Shape>(); Square square = new Square(4); shape.Add(square); Triangle triangle = new Triangle(7.8, 4.8); shape.Add(triangle); Rectangle rectangle = new Rectangle(8, 5.7); shape.Add(rectangle); foreach (var item in shape) { Console.WriteLine(item.GetType().Name + " surfase is " + item.CalculateSurface()); } }
static void Main(string[] args) { Point centreRect = new Point(1, 1); Point centreSquare = new Point(0, 0); Rectangle rect = new Rectangle(3, 5, centreRect); Square square = new Square(2, centreSquare); Ellipse ellipse = new Ellipse(2, 1, centreSquare); Console.WriteLine(rect.ToString()); Console.WriteLine(rect.GetArea() + " " + rect.GetPerimeter()); Console.WriteLine(square.ToString()); Console.WriteLine(square.GetArea() + " " + square.GetPerimeter()); Console.WriteLine(ellipse.ToString()); Console.WriteLine(ellipse.GetArea() + " " + ellipse.GetPerimeter()); }
public static void Main() { var shapes = new List<Shape>(); var square = new Square(10); var rectangle = new Rectangle(5.5, 6.5); var triangle = new Triangle(new Point(1, 5), new Point(3, 7), new Point(8, 3)); var ellipse = new Ellipse(3, 7); var circle = new Circle(5.5); shapes.Add(circle); shapes.Add(ellipse); shapes.Add(triangle); shapes.Add(rectangle); shapes.Add(square); foreach (var shape in shapes) { Console.WriteLine(shape.ToString()); Console.WriteLine(); } }
public static void Main(string[] args) { GeometricFigure[] g = new GeometricFigure[3]; g[0] = new Rectangle(10,20).ComputeArea(); g[1] = new Square(5).ComputeArea(); g[2] = new Triangle(5,10).ComputeArea(); Console.WriteLine("displaying datas..."); DisplayData(g); for (int i=0; i<g.Length; i++) { g[i].Height = i*12+1; g[i].ComputeArea(); } Console.WriteLine("changed stuff...redisplaying"); DisplayData(g); }
static void Main(string[] args) { Square x = new Square(5); Circle c = new Circle(3.5); Triangle t = new Triangle(3, 4, 5); Rectangle r = new Rectangle(5, 2.5); //make list List<IShape> shapes = new List<IShape>(); shapes.Add(x); shapes.Add(c); shapes.Add(t); shapes.Add(r); //print out foreach (IShape shape in shapes) { Console.WriteLine(shape); } Console.ReadLine(); }
static void Main(string[] args) { #region Circles // create new Circle Circle c1 = new Circle(); Circle c2 = new Circle(); Circle c3 = new Circle(); // ToString tests Console.WriteLine("Circle1:\n" + c1.ToString()); Console.WriteLine("Circle2:\n" + c2.ToString()); Console.WriteLine("Circle3:\n" + c3.ToString()); // Equals tests Console.WriteLine("Does Circle1 equal Circle2? {0}", c1.Equals(c2)); Console.WriteLine("Does Circle1 equal Circle3? {0}", c1.Equals(c3)); Console.WriteLine("Does Circle2 equal Circle3? {0}", c2.Equals(c3) + "\n"); #endregion #region Squares // create new Squares Square s1 = new Square(); Square s2 = new Square(); Square s3 = new Square(); // ToString tests Console.WriteLine("Square1:\n" + s1.ToString()); Console.WriteLine("Square2:\n" + s2.ToString()); Console.WriteLine("Square3:\n" + s3.ToString()); // Equals tests Console.WriteLine("Does Square1 equal Square2? {0}", s1.Equals(s2)); Console.WriteLine("Does Square1 equal Square3? {0}", s1.Equals(s3)); Console.WriteLine("Does Square2 equal Square3? {0}", s2.Equals(s3) + "\n"); #endregion Console.ReadLine(); }
public static void Main() { var arrayOfSquares = new Square[] { new Square(5.5), new Square(6.7), new Square(9.8) }; var arrayOfTriangles = new Triangle[] { new Triangle(5.5, 6.5), new Triangle(15.4, 21.4), new Triangle(3.5, 2.1) }; var arrayOfRectangles = new Rectangle[] { new Rectangle(1.2, 2.5), new Rectangle(22.15, 15.5), new Rectangle(17.2, 10) }; //First variant Console.WriteLine("Calculating the surface of the squares:"); PrintSurface(arrayOfSquares); Console.WriteLine("Calculating the surface of the triangles:"); PrintSurface(arrayOfTriangles); Console.WriteLine("Calculating the surface of the rectangles:"); PrintSurface(arrayOfRectangles); ////Second variant //var listOfSurfacesOfSquares = Surfaces(arrayOfSquares); //Console.WriteLine(string.Join("\n", listOfSurfacesOfSquares)); }
static void Main() { Triangle triangle = new Triangle(2, 3); Rectangle rectangle = new Rectangle(2, 3); Square square = new Square(2); Console.WriteLine("Triangle area is {0}", triangle.CalculateSurface()); Console.WriteLine("Rectangle area is {0}", rectangle.CalculateSurface()); Console.WriteLine("Square area is {0}", square.CalculateSurface()); //Write a program that tests the behaviour of the CalculateSurface() method //for different shapes (Square, Rectangle, Triangle) stored in an array Shape[] all = new Shape[] { new Triangle (2,3), new Rectangle(2,3), new Square (3) }; foreach (Shape shape in all) { Console.WriteLine("{0} is the area of the object {1}", shape.CalculateSurface(), shape.GetType()); } }
static void Main(string[] args) { int opt = -1; while (opt != 0) { Console.WriteLine("Program Bentuk-Bentuk : "); Console.WriteLine("============================================================"); Console.WriteLine("1. Persegi Sama Sisi"); Console.WriteLine("2. Ubin (Turuan Dari Persegi Sama Sisi)"); Console.WriteLine("3. Eternit / Plafon (Turuan Dari Persegi Sama Sisi)"); Console.WriteLine("4. Kubus (Turuan Dari Persegi Sama Sisi 3D)"); Console.WriteLine("............................................................"); Console.WriteLine("5. Persegi Panjang"); Console.WriteLine("6. Papan Tulis (Turuan Dari Persegi Panjang)"); Console.WriteLine("7. Pintu (Turuan Dari Persegi Panjang)"); Console.WriteLine("8. Balok (Turuan Dari Persegi Panjang 3D)"); Console.WriteLine("............................................................"); Console.WriteLine("9. Lingkaran"); Console.WriteLine("10. Bola"); Console.WriteLine("11. Kerucut"); Console.WriteLine("............................................................"); Console.WriteLine("0. Keluar"); Console.WriteLine("------------------------------------------------------------"); Console.Write("Pilih Opsi : "); opt = Convert.ToInt32(Console.ReadLine()); switch (opt) { case 1: Square sqr1 = new Square(); sqr1.input().display(); break; case 2: Tile tle1 = new Tile(); tle1.input().display(); break; case 3: Plasterboard plb = new Plasterboard(); plb.input().display(); break; case 4: Cube cube = new Cube(); cube.input().display(); break; case 5: Rectangle rct1 = new Rectangle(); rct1.input().display(); break; case 6: WhiteBoard whtb = new WhiteBoard(); whtb.input().display(); break; case 7: Door door = new Door(); door.input().display(); break; case 8: Block block = new Block(); block.input().display(); break; case 9: Circle circle = new Circle(); circle.input().display(); break; case 10: Sphere sphere = new Sphere(); sphere.input().display(); break; case 11: Cone cone = new Cone(); cone.input().display(); break; default: break; } Console.WriteLine("\n\n"); } }
public void TestConstructSetAllFourSides() { Square mySquare = new Square(4); Assert.AreEqual(4,mySquare.Top); }
public void TestSquarePerimeterIsZero() { Square square = new Square(); square.Perimeter(); }
public void SquareAreaTest() { Square s = new Square(5); Assert.AreEqual(25, s.Area()); }
public static void Main() { int tr_side1 = 0; int tr_side2 = 0; int tr_side3 = 0; double tr_angle = 0; int c_radius = 0; int sq_side = 0; Console.WriteLine("Select the number of shape, that need to calculate Area and Perimetr: \n1.Square \n2.Triangle \n3.Circle"); int choise = int.Parse(Console.ReadLine()); switch (choise) { case 1: Console.WriteLine("Enter a square's side"); sq_side = int.Parse(Console.ReadLine()); break; case 2: Console.WriteLine("Enter a triangle's first side"); tr_side1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter a triangle's second side"); tr_side2 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter a triangle's trird side"); tr_side3 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter a triangle's angle beside 1st and 2nd side"); tr_angle = int.Parse(Console.ReadLine()); break; case 3: Console.WriteLine("Enter a circle's radius"); c_radius = int.Parse(Console.ReadLine()); break; } Shape square = new Square(sq_side, "Square"); Shape tr = new Triangle(tr_side1, tr_side2, tr_side3, tr_angle, "Triangle"); Shape circle = new Circle(c_radius, "Circle"); if (choise == 1) { Console.WriteLine(square); } else if (choise == 2) { if (tr_angle > 180 || tr_angle < 0) { Console.WriteLine("Incorrect value"); } else { Console.WriteLine(tr); } } else if (choise == 3) { Console.WriteLine(circle); } else { Console.WriteLine("Incorrect entered number"); } Console.ReadLine(); }
public void TestSquareDefaultColors() { Square square = new Square(); Assert.AreEqual(Color.DeepSkyBlue, square.BorderColor); Assert.AreEqual(Color.Khaki, square.FillColor); }
public void TestSquareConstructor() { // test that sides are set to 0 by default if a value is not specified Square mySquare = new Square(); Assert.AreEqual(0, mySquare.Top); }
public void TestSquareComputePerimeter() { Square mySquare = new Square(10); mySquare.Top = 5; Assert.AreEqual(20, mySquare.Perimeter()); }
static void Main(string[] args) { Square square = new Square(); square.Draw(); Console.ReadLine(); }
public void SquareContructorCanComputeArea() { var square = new Square(5); Assert.AreEqual(square.Area(), 25); }
public void TestSquareAreaIsZero() { Square square = new Square(); square.Area(); }
public void TestMethod1() { var mySq = new Square(4); Assert.AreEqual(16, mySq.Area()); Assert.AreEqual(16, mySq.Perimeter()); }
public void TestSquareConstructor2() { // test that you cannot set a side to be a negative or zero value Square square = new Square(); square.Top = -2; }