Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Jul 2017 |
Last Sign in: | 210 Weeks Ago, 4 Days Ago |
Questions Answered: | 15833 |
Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Ive been mulling over this assignment for a while now. I cant figure out if its a naming issue or if my methods are returning the wrong values or what.
Â
Â
Â
Â
Prompt: This assignment provides an opportunity to work with defining classes and creating objects (instantiating) from those classes. The exercise consists of source code that contains errors; therefore, it neither compiles nor runs correctly. It focuses on a console application, but the concepts translate across C# programming. Consider the following C# console program that contains four programming errors. For the sake of simplicity and space, two classes are defined in the same file as opposed to the best practice of defining one class per file:Â
Â
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
#endregion
namespace Classes
{
  class Program
  {
    static void Main(string[] args)
    {
      Point origin = new Point();
      Point bottomRight = another Point(1366, 768);
      double distance = origin.DistanceTo(bottomRight);
      Console.WriteLine("Distance is: {0}", distance);
      Console.WriteLine("Number of Point objects: {0}", Point.ObjectCount());
    }
  }
  class Point
  {
    private int x, y;
    private int objectCount = 0;
    public void Point()
    {
      this.x = -1;
      this.y = -1;
      objectCount++;
    }
    public Point(int x, int y)
    {
      this.x = x;
      this.y = y;
      objectCount++;
    }
    private double DistanceTo(Point other)
    {
      int xDiff = this.x - other.x;
      int yDiff = this.y - other.y;
      double distance = Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff));
      return distance;
    }
    public static int ObjectCount()
    {
      return ObjectCount;
    }
  }
}
----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------Tha-----------nk -----------you----------- fo-----------r y-----------our----------- in-----------ter-----------est----------- an-----------d b-----------uyi-----------ng -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll -----------be -----------qui-----------ckl-----------y