Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@Evan a class is a generalized container for your things. A car, a person, a point (in your case).</p> <p>Everytime you want to "create" one or more object of your defined class, you instantiate them:</p> <pre><code>Person evan = new Person(); Person rob = new Person(); </code></pre> <p>both of us are person, you don't really need to define class <code>Person1</code> and <code>Person2</code>!</p> <p>And in a class you should define the methods used to "relate" to other similar objects. For example:</p> <pre><code>// In Person.java public void greet(Person p) { System.out.println("My name is "+this.name+". Nice to meet you +"p.getName()); } // In main rob.greet(evan); // it now gives compile errors of course but take the point :P </code></pre> <p>What you want to achieve is to create a better and more complete <code>Point</code> class with all the methods you want to use. In the end, just initialize more <code>Point</code> objects (same class!) in your main and play with them.</p> <p>Hope it helps :)</p> <p><strong>EDIT</strong></p> <p>Ok, perhaps I've got what your homework wants you to perform.</p> <p>A "parameter-less" method <code>measureDistance()</code> should make you wonder <em>one</em> important thing: "distance FROM which point????".</p> <p>Obviously, if the function takes no parameters all the information needed to that calculus must be in the object which calls it. Don't you think?</p> <p>So, you probably want to achieve a secondary class (if you really need to define it as <code>Point2</code> it's ok, but change that name because it's confusing) which can take a <code>Point</code> in its constructor (saving this information in itself) and then use that Point to measure distance from it.</p> <p><strong>Example</strong></p> <pre><code>public class Point2{ private int a; private int b; private Point startingPoint; public Point2(int a, int b, Point p){ this.a = a; this.b = b; startingPoint = p; } // Computes the distance from starting point to this public double measureDistance(){//it takes no parameter. return startingPoint.distanceTo(a, b); } /* if you can't edit distanceTo() it gets a little verbose but you must create a Point with Point2 coordinates - remember this example when you will study Inheritance public double measureDistance() { Point endingPoint = new Point(a, b); return startingPoint.distanceTo(endingPoint); } */ } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload