Hi, i need to create a class which calculates the distance between two points. I am stuck and i am a total beginner. Here are my classes:
package org.totalbeginner.tutorial;
public class Punkt {
public double x;
public double y;
Punkt(double xkoord, double ykoord){
this.x = xkoord;
this.y = ykoord;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}
package org.totalbeginner.tutorial;
The second class.
package org.totalbeginner.tutorial;
public class Strecke{
double x;
double y;
Punkt p1 = new Punkt(2.0,2.0);
Punkt p2 = new Punkt(4.0,4.0);
Punkt mp = new Punkt(x,y);
public void mittelpunkt(){
x = (p1.getX() + p2.getX()) / 2;
y = (p1.getY() + p2.getY()) / 2;
}
}
I am a total programmer newbie and i am not sure how to get a point object (the middlepoint) between both defined points. it is part of my java class, so yes it is somekind of homework.
I can create point objects but i am not sure how to return a point object through my mittelpunkt() method that lies between those two point objects. Yes i am fully aware that this is totally trivial question, but i am just at the beginning. Don't hate me because i am worthless :)