V main už nemám nic. Čistě jen ty dva body + to co si mi napsal ty.
Metoda Bod:
public class Bod
{
private double x;
private double y;
public Bod()
{
x=0;
y=0;
}
public Bod(double x, double y){
this.x = x;
this.y = y;
}
public String toString()
{
String string = "\nx: "+ getX() + " Y: "+ getY();
return string;
}
public void tisk()
{
System.out.println("Souradnice bodu jsou: "+ this.toString());
}
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = y;
}
public double delkaX(Bod bod){
return Math.abs(getX() - bod.getX());
}
}
Metoda Vypocet:
public class Vypocet
{
private Bod bod1;
private Bod bod2;
public Vypocet(){
bod1 = new Bod();
bod2 = new Bod();
}
public Vypocet(Bod a, Bod b){
bod1 = a;
bod2 = b;
}
public Bod getBod1(){
return bod1;
}
public void setBod1(Bod a){
bod1 = a;
}
public Bod getBod2(){
return bod2;
}
public void setBod2(Bod b){
bod2 = b;
}
public static double vzdalenost(Bod b1, Bod b2){
double delkaX, delkaY;
delkaX = b2.getX() - b1.getX();
delkaY = b2.getY() - b1.getY();
return Math.sqrt(delkaX*delkaX + delkaY*delkaY);
}
public String toString(){
return String.format("\nBod x: %s,\nBod y: %s,\nDelka usecky: %.10f ", bod1.toString(), bod2.toString(), vzdalenost(bod1, bod2));
}
public void tisk(){
System.out.println(this.toString());
}
}
A metoda s main:
public class VypocetTest
{
public static void main(String[] args){
Bod bod1 = new Bod(90, 40);
Bod bod2 = new Bod(50, 10);
double v = vzdalenost(bod1, bod2);a
}
}