Friday, March 30, 2012

I Did It!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise_7_4
{
    class Point
    {
        public int x;
        public int y;
        public Point(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        public void DisplayPoint()
        {
            Console.WriteLine("In DisplayPoint()");
            Console.WriteLine("Point at ({0},{1})", x, y);
        }
    }
    class Square
    {
        Point topLeft;
        Point topRight;
        Point bottomLeft;
        Point bottomRight;
        public Square(Point startingPoint, int sideLength)
        {
            this.topLeft = new Point(startingPoint.x, startingPoint.y);
            this.topRight = new Point(startingPoint.x + sideLength, startingPoint.y);
            this.bottomLeft = new Point(startingPoint.x, startingPoint.y - sideLength);
            this.bottomRight = new Point(startingPoint.x + sideLength, startingPoint.y - sideLength);
        }
        public void DisplaySquare()
        {
            Console.WriteLine("In DisplaySquare()");
            topLeft.DisplayPoint();
            topRight.DisplayPoint();
            bottomLeft.DisplayPoint();
            bottomRight.DisplayPoint();
        }
    }
   
    class Program
    {
        static void Main(string[] args)
        {
            Point myPoint = new Point(3, 4);
            myPoint.DisplayPoint();
            Square mySquare = new Square(myPoint, 5);
            mySquare.DisplaySquare();
            //to keep console window open to view output
            Console.ReadLine();
        }
    }
}

Output:  (really basic, I know...)
In DisplayPoint()
Point at (3,4)
In DisplaySquare()
In DisplayPoint()
Point at (3,4)
In DisplayPoint()
Point at (8,4)
In DisplayPoint()
Point at (3, -1)
In DisplayPoint()
Point at (8, -1)

There are a ton of things I want to refactor (including the order in which the points are "drawn"), but I'm just so happy I got it!  :D

No comments:

Post a Comment

Comments? Questions? Complaints? Coladas?