ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 25 Apr 2017 My Price 9.00

Severity Code Description Project File Line Suppression State

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace ConsoleApplication2

{

  class Program

  {

   

      static void Main(string[] args)

      {

        Point origin = new Point();

        Point bottomRight = new Point(1366, 768);

        double distance = origin.DistanceTo(bottomRight);

        Console.WriteLine($"Distance is: {distance}");

        Console.WriteLine($"Number of Point objects: {Point.ObjectCount()}");

      }

    }

    class Point

    {

      private int x, y;

      private int objectCount = 0;

      public Point()

      {

        this.x = -1;

        this.y = -1;

        objectCount++;

      }

      public Point(int x, int y)

      {

        this.x = x;

        this.y = y;

        objectCount++;

      }

      public 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;

      }

    }

  }

 

I am getting this error

 

Severity Code Description Project File Line Suppression State

Error CS0120 An object reference is required for the non-static field, method, or property 'Point.objectCount' ConsoleApplication2 C:UsersTrey PerrymanDocumentsConsoleApplication2ConsoleApplication2Program.cs 46 Active

Attachments:

Answers

(11)
Status NEW Posted 25 Apr 2017 06:04 AM My Price 9.00

-----------

Not Rated(0)