static void Main(string[] args) { ShapeManager manager1 = new ShapeManager(); manager1.AddShape(new Circle(2.5f)); manager1.AddShape(new Circle(ConsoleColor.Red, 10)); manager1.AddShape(new Ellipse(2, 4)); manager1.AddShape(new Ellipse(ConsoleColor.Magenta, 2, 4)); manager1.AddShape(new Rectangle(4, 5)); manager1.AddShape(new Rectangle(ConsoleColor.DarkYellow, 8.25f, 2.5f)); Console.WriteLine("Overall number of shapes in list: {0}.", manager1.Count); manager1.DisplayAll(); Console.BackgroundColor = ConsoleColor.Black; StringBuilder sb = new StringBuilder(); manager1.Save(sb); Console.WriteLine(sb.ToString()); manager1.ShapeCompare((IComparable)manager1[1], (IComparable)manager1[2]); manager1.ShapeCompare((IComparable)manager1[3], (IComparable)manager1[3]); manager1.ShapeCompare((IComparable)manager1[3], (IComparable)manager1[4]); manager1.WriteSortedShapeList(); }
static void Main(string[] args) { ShapeManager shapes = new ShapeManager(); shapes.Add(new Circle(5)); shapes.Add(new Rectangle(2.7, 8)); shapes.Add(new Ellipse(3.5, 10)); shapes.Add(new Rectangle(5, 7)); shapes.Add(new Rectangle(17.5, 2)); shapes.Add(new Ellipse(6, 3.5)); shapes.Add(new Ellipse(3, 7)); Rectangle rect = new Rectangle(2.5, 4); Console.WriteLine($"{rect.CompareTo(new Rectangle(4, 2.5))}"); Console.WriteLine($"There are {shapes.Count} shapes."); shapes.DisplayAll(); shapes[1].Display(); StringBuilder sb = new StringBuilder(); shapes.Save(sb); Console.WriteLine($"{sb.ToString()}"); Console.WriteLine($"{shapes[1].CompareTo(shapes[3])}"); Console.Read(); }
private static void Main(string[] args) { ShapeManager shapeManager = new ShapeManager(); shapeManager.Add(new Circle(4)); Rectangle rectangle = new Rectangle(6, 8); rectangle.Color = ConsoleColor.DarkGreen; shapeManager.Add(rectangle); shapeManager.Add(new Ellipse(5, 10)); shapeManager.Add(new Circle(12)); shapeManager.DisplayAll(); Console.WriteLine("Shapes count: {0}", shapeManager.Count); StringBuilder sb = new StringBuilder(); shapeManager.Save(sb); Console.WriteLine(sb.ToString()); ShapeManager rectangleManager = new ShapeManager(); rectangleManager.Add(new Rectangle(4, 5)); rectangleManager.Add(new Rectangle(1, 2)); rectangleManager.Add(new Rectangle(5, 3)); rectangleManager.Add(new Rectangle(8, 7)); //rectangleManager.Sort(); rectangleManager.DisplayAll(); Console.ReadLine(); }
static void Main(string[] args) { ShapeManager mgr = new ShapeManager(); mgr.Add(new Circle(5)); mgr.Add(new Ellipse(3, 4, ConsoleColor.Blue)); mgr.Add(new Rectangle(3, 4, ConsoleColor.DarkYellow)); mgr.Add(new Circle(5, ConsoleColor.Red)); mgr.DisplayAll(); StringBuilder sb = new StringBuilder("Log:\n"); mgr.Save(sb); Console.WriteLine(sb.ToString()); Rectangle rec = new Rectangle(5, 8); Rectangle otherRec = new Rectangle(2, 3); rec.Display(); otherRec.Display(); Console.ReadKey(); }
/// <summary> /// Create an instance of ShapeManager /// Add several different shapes to the ShapeManager you just created /// Call DisplayAll and make sure you get the expected result. /// (5.2.) call the Save method and display the resulting StringBuilder using its ToString method. /// Test my implementations /// </summary> /// <param name="args"></param> static void Main(string[] args) { ShapeManager shapeManager = new ShapeManager(); //not acceptable constructors - Circle c_1 = new Circle(-1); Circle c_2 = new Circle(0, ConsoleColor.DarkRed); Elipse e_1 = new Elipse(-6, 1); Elipse e_2 = new Elipse(-3, -5, ConsoleColor.DarkGreen); Elipse e_3 = new Elipse(7, 0); Rectangle r_1 = new Rectangle(-1, -3); Rectangle r_2 = new Rectangle(2, 0, ConsoleColor.DarkYellow); Rectangle r_3 = new Rectangle(-1, 3); //they only alarm when they are consructed because i did'nt used exeptions //I will do it in the next lab. //the valid constructors Circle c1 = new Circle(); Circle c2 = new Circle(2, ConsoleColor.Red); Elipse e1 = new Elipse(); Elipse e2 = new Elipse(3, 5, ConsoleColor.Green); Elipse e3 = new Elipse(6, 7); Rectangle r1 = new Rectangle(); Rectangle r2 = new Rectangle(2, 6, ConsoleColor.Yellow); Rectangle r3 = new Rectangle(1, 3); shapeManager.Add(c1); shapeManager.Add(c2); shapeManager.Add(e1); shapeManager.Add(e2); shapeManager.Add(e3); shapeManager.Add(r1); shapeManager.Add(r2); shapeManager.Add(r3); Console.WriteLine($"we create Shape manager and insert {shapeManager.Count} shpes"); shapeManager.DisplayAll(); // call the Save method and display the resulting StringBuilder using its ToString method. StringBuilder sb = new StringBuilder(); Console.WriteLine("we used a StringBuilder and save to him this text \n about all the shapes in our shape menger: "); shapeManager.save(sb); Console.WriteLine(sb.ToString()); //checking CompareTo Circle c1blue = new Circle(1, ConsoleColor.Blue); if (c1blue.CompareTo(c1) == 0) { Console.WriteLine("the circle c1:"); c1.Display(); Console.WriteLine("and the circle c1blue:"); c1blue.Display(); Console.WriteLine("are equal according to CompareTo"); } else { Console.WriteLine("CompareTo error"); } if (r2.CompareTo(r3) > 0) { Console.WriteLine("the Rectangle r2:"); r1.Display(); Console.WriteLine("is bigger then Rectangle r3:"); r3.Display(); } else { Console.WriteLine("CompareTo error"); } }
static void Main(string[] args) { ShapeManager sm = new ShapeManager(); sm.Add(new Rectangle(3.4, 5.2, ConsoleColor.Red)); sm.Add(new Rectangle(4, 5, ConsoleColor.DarkBlue)); sm.Add(new Ellipse(2.5, 4, ConsoleColor.Blue)); sm.Add(new Circle(5)); sm.DisplayAll(); }
public static void Main() { var shm = new ShapeManager(); shm.Add(new Rectangle(5, 4)); shm.Add(new Ellipse(5, 10, ConsoleColor.Cyan)); shm.Add(new Circle(5, ConsoleColor.Yellow)); shm.DisplayAll(); }
static void Main(string[] args) { ShapeManager sm = new ShapeManager(); StringBuilder sb = new StringBuilder(); sm.Add(new Rectangle(3.4, 5.2, ConsoleColor.Red)); sm.Add(new Rectangle(4, 5, ConsoleColor.DarkBlue)); sm.Add(new Ellipse(2.5, 4, ConsoleColor.Blue)); sm.Add(new Circle(5)); sm.Save(sb); Console.WriteLine(sb.ToString()); }
static void Main(string[] args) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Values is:"); ShapeManager sm = new ShapeManager(); Shape r1 = new Rectangle(4, 6, ConsoleColor.Red); Shape e1 = new Ellipse(3, 6, ConsoleColor.Blue); Shape c1 = new Circle(6, 6, ConsoleColor.Green); sm.Add(r1); sm.Add(e1); sm.Add(c1); sm.DisplayAll(); }
static void Main(string[] args) { Ellipse elli = new Ellipse(5, 3, ConsoleColor.Green); Rectangle recta = new Rectangle(5, 3); ShapeManager shapeManager = new ShapeManager(); shapeManager.Add(elli); shapeManager.Add(recta); shapeManager.Add(new Circle(5, ConsoleColor.Blue)); StringBuilder c = new StringBuilder(); shapeManager.Save(c); Console.WriteLine("the area of the rectangle is " + recta.CompareTo(elli) + " than the area of the ellipse"); shapeManager.DisplayAll(); }
static void Main(string[] args) { ShapeManager mngr = new ShapeManager(); StringBuilder sb = new StringBuilder(); mngr.Add(new Circle(5, ConsoleColor.Cyan)); mngr.Add(new Rectangle(2, 3, ConsoleColor.Blue)); mngr.Add(new Ellipse(5, 6, ConsoleColor.Green)); //Console.WriteLine($"There are {mngr.Count} Shapes: \n"); //from lab5.1 //mngr.DisplayAll(); mngr.Save(sb); // from lab 5.2 Console.WriteLine(sb.ToString()); // mngr.Add(new Circle(5, ConsoleColor.Red)); mngr.Add(new Rectangle(6, 7, ConsoleColor.Cyan)); mngr.Add(new Ellipse(1, 2, ConsoleColor.Blue)); switch (((Circle)mngr[0]).CompareTo(mngr[3])) { case 1: ((Circle)mngr[3]).Dispaly(); Console.WriteLine("is greater than"); ((Circle)mngr[0]).Dispaly(); break; case -1: ((Circle)mngr[0]).Dispaly(); Console.WriteLine("is greater than"); ((Circle)mngr[3]).Dispaly(); break; case 0: ((Circle)mngr[0]).Dispaly(); Console.WriteLine("is is equal to"); ((Circle)mngr[3]).Dispaly(); break; } }
internal static void Main() { var shm = new ShapeManager(); shm.Add(new Rectangle(8, 9, ConsoleColor.Blue)); shm.Add(new Rectangle(5, 4)); shm.Add(new Ellipse(8, 4, ConsoleColor.Yellow)); shm.Add(new Circle(2, ConsoleColor.Magenta)); shm.DisplayAll(); Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine(); Console.WriteLine("Before sorting"); var sb = new StringBuilder(); shm.Save(sb); Console.WriteLine(sb.ToString()); Console.WriteLine(); try { shm.Shapes.Sort(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("After sorting"); var sb2 = new StringBuilder(); shm.Save(sb2); Console.WriteLine(sb2.ToString()); }
static void Main(string[] args) { //Define Shapes Rectangle shape1 = new Rectangle(10,15); Rectangle shape2 = new Rectangle(20,5); Rectangle shape3 = new Rectangle(5,30); Ellipse shape4 = new Ellipse(5,5); Ellipse shape5 = new Ellipse(9,30); Ellipse shape6 = new Ellipse(99,20); Circle shape7 = new Circle(5); Circle shape8 = new Circle(9); Circle shape9 = new Circle(99); //Adding New shapes to list ShapeManager shapeManager = new ShapeManager(); shapeManager.Add(shape1); shapeManager.Add(shape2); shapeManager.Add(shape3); shapeManager.Add(shape4); shapeManager.Add(shape5); shapeManager.Add(shape6); shapeManager.Add(shape7); shapeManager.Add(shape8); shapeManager.Add(shape9); Console.WriteLine("Display Method"); shapeManager.DisplayAll(); Console.WriteLine(); Console.WriteLine("Save Method"); Console.WriteLine(shapeManager.Save()); Console.ReadLine(); }
static void Main(string[] args) { try { ShapeManager sm = new ShapeManager(); sm.add(new Rectangle(5, 4)); sm.add(new Circle(3)); sm.add(new Elipse(3, 3)); sm.add(new Rectangle(5, 6)); sm.add(new Elipse(6, 8)); sm.add(new Circle(4)); sm.DisplayAll(); Shape s = sm[0]; Rectangle r = (Rectangle)s; StringBuilder sb = new StringBuilder(); sm.Save(sb); Console.WriteLine(sb.ToString()); Rectangle r1 = (Rectangle)sm[0]; Rectangle r2 = (Rectangle)sm[3]; Console.WriteLine(r2.CompareTo(r1)); Elipse e1 = (Elipse)sm[2]; Elipse e2 = (Elipse)sm[4]; Console.WriteLine(e2.CompareTo(e1)); Circle c1 = (Circle)sm[1]; Circle c2 = (Circle)sm[5]; Console.WriteLine(c1.CompareTo(e1)); c1.Display(); Console.WriteLine(sm.Count); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { ShapeManager shapeManager = new ShapeManager(); int choice = 0, i, j; double height, width; printMenue(); choice = int.Parse(Console.ReadLine()); while (choice != 0) { switch (choice) { case 1: Console.WriteLine("enter height and width"); height = int.Parse(Console.ReadLine()); width = int.Parse(Console.ReadLine()); shapeManager.Add(new Rectangle(height, width)); break; case 2: Console.WriteLine("enter height radius and width radius"); height = int.Parse(Console.ReadLine()); width = int.Parse(Console.ReadLine()); shapeManager.Add(new Ellipse(height, width)); break; case 3: Console.WriteLine("enter radius"); height = int.Parse(Console.ReadLine()); shapeManager.Add(new Circle(height)); break; case 4: shapeManager.DisplayAll(); break; case 5: Console.WriteLine("enter 2 indexes to compare: "); i = int.Parse(Console.ReadLine()); j = int.Parse(Console.ReadLine()); if (i >= shapeManager.Count || j >= shapeManager.Count) { Console.WriteLine("index out of range!"); break; } IComparable shape1 = shapeManager[i] as IComparable; IComparable shape2 = shapeManager[j] as IComparable; try { if (shape1 == null && shape2 as IComparable == null) { Console.WriteLine("Error! not icomperable!"); break; } else if (shape1 == null) { if (shape2.CompareTo(shapeManager[i]) == 0) { Console.WriteLine("equal"); } else { Console.WriteLine("not equal"); } } else { if (shape1.CompareTo(shapeManager[j]) == 0) { Console.WriteLine("equal"); } else { Console.WriteLine("not equal"); } } } catch (InvalidCastException ex) { Console.WriteLine(ex.Message); } break; case 6: Console.WriteLine("enter string to add"); StringBuilder sb = new StringBuilder(Console.ReadLine()); shapeManager.Save(sb); break; } printMenue(); choice = int.Parse(Console.ReadLine()); } }
public AddShapeCommand(ShapeManager sm, Shape shape) { _mgr = sm; _shape = shape; }
public RemoveShapeCommand(ShapeManager mgr, Shape shape) : base(mgr, shape) { }
static void Main(string[] args) { var sm = new ShapeManager(); var cmdMgr = new CommandManager(); sm.Add(new Rectangle(10, 3, ConsoleColor.Green)); sm.Add(new Circle(5, ConsoleColor.Red)); sm.Add(new Square(8, ConsoleColor.Blue)); var group = new ShapeGroup(); group.Add(new Circle(10)); group.Add(new Rectangle(6, 8, ConsoleColor.Cyan)); sm.Add(group); var group2 = new ShapeGroup(); group2.Add(new Square(12, ConsoleColor.DarkGray)); group2.Add(new Circle(6)); group.Add(group2); var rnd = new Random(); bool done = false; while (!done) { int n; Console.WriteLine(); Console.Write("A=Add, E=Remove, D=Display, M=Move, U=Undo, R=Redo, Q=Quit: "); switch (Console.ReadLine().ToUpper()) { case "D": sm.Display(Console.Out); break; case "Q": done = true; break; case "M": n = GetShapeNumber(); Console.Write("X Offset: "); int dx = int.Parse(Console.ReadLine()); Console.Write("Y Offset: "); int dy = int.Parse(Console.ReadLine()); var cmd = new MoveCommand(sm[n], dx, dy); cmdMgr.Add(cmd); break; case "U": if (!cmdMgr.CanUndo) { Console.WriteLine("Cannot undo!"); } else { cmdMgr.Undo(); } break; case "R": if (!cmdMgr.CanRedo) { Console.WriteLine("Cannot redo!"); } else { cmdMgr.Redo(); } break; case "A": Shape shape = null; switch (rnd.Next(3)) { case 0: shape = new Square(rnd.Next(10) + 5); break; case 1: shape = new Circle(rnd.Next(10) + 2); break; case 2: shape = new Rectangle(rnd.Next(10) + 1, rnd.Next(10) + 3); break; } cmdMgr.Add(new AddShapeCommand(sm, shape)); break; case "E": n = GetShapeNumber(); cmdMgr.Add(new RemoveShapeCommand(sm, sm[n])); break; } } }
static void Main(string[] args) { ShapeManager M_shape = new ShapeManager(); Shape r1 = new Rectangle(ConsoleColor.Blue, 7, 8); Rectangle r2 = new Rectangle(ConsoleColor.DarkRed, 6, 9); Shape e1 = new Ellipse(ConsoleColor.Green, 5, 6); Ellipse e2 = new Ellipse(ConsoleColor.DarkYellow, 1, 4); Shape c1 = new Circle(ConsoleColor.Magenta, 5); Circle c2 = new Circle(ConsoleColor.Yellow, 8); //Add Method M_shape.Add(r1); M_shape.Add(r2); M_shape.Add(e1); M_shape.Add(e2); M_shape.Add(c1); M_shape.Add(c2); Console.WriteLine("DisplayAll test:"); Console.WriteLine("------------------"); M_shape.DisplayAll(); Console.WriteLine("Indexer tests:"); Console.WriteLine("---------------"); Console.WriteLine(M_shape[1]); Console.WriteLine(M_shape[3]); Console.WriteLine(M_shape[5]); Console.WriteLine("\n\n"); //StringBuilder StringBuilder sb = new StringBuilder(); M_shape.Save(sb); Console.WriteLine("IPersist"); Console.WriteLine("----------"); Console.WriteLine(sb.ToString()); Console.WriteLine(); Console.WriteLine("IComperable Tests:"); Console.WriteLine("------------------"); Ellipse e_1 = new Ellipse(ConsoleColor.DarkYellow, 8, 0); Ellipse e_2 = new Ellipse(ConsoleColor.DarkYellow, 5, 0); Shape c_1 = new Circle(ConsoleColor.Magenta, 8); Circle c_2 = new Circle(ConsoleColor.Yellow, 8); Shape r_1 = new Rectangle(ConsoleColor.Blue, 7, 8); Rectangle r_2 = new Rectangle(ConsoleColor.DarkRed, 6, 9); //1 Console.WriteLine("Ellipse and Ellipse"); int result = e_1.CompareTo(e_2); if (result == 0) { Console.WriteLine("The same kind of shape!!!\n"); } else if (result == -1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 10) { Console.WriteLine("Not the same kind of shape!!!\n"); } //2 Console.WriteLine("Ellipse and Rectangle"); result = e_2.CompareTo(r_1); if (result == 0) { Console.WriteLine("The same kind of shape!!!\n"); } else if (result == -1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 10) { Console.WriteLine("Not the same kind of shape!!!\n"); } //3 Console.WriteLine("Rectangle and Ellipse"); result = r_2.CompareTo(e_2); if (result == 0) { Console.WriteLine("The same kind of shape!!!\n"); } else if (result == -1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 10) { Console.WriteLine("Not the same kind of shape!!!\n"); } //4 Console.WriteLine("Rectangle and Rectangle"); result = r_2.CompareTo(r_1); if (result == 0) { Console.WriteLine("The same kind of shape!!!\n"); } else if (result == -1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 10) { Console.WriteLine("Not the same kind of shape!!!\n"); } //5 Console.WriteLine("Rectangle and Circle"); result = r_2.CompareTo(c_1); if (result == 0) { Console.WriteLine("The same kind of shape!!!\n"); } else if (result == -1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 10) { Console.WriteLine("Not the same kind of shape!!!\n"); } //6 Console.WriteLine("Ellipse and Circle"); result = e_2.CompareTo(c_1); if (result == 0) { Console.WriteLine("The same kind of shape!!!\n"); } else if (result == -1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 1) { Console.WriteLine("Not the same kind of shape!!!\n"); } else if (result == 10) { Console.WriteLine("Not the same kind of shape!!!\n"); } }