From c744258ef3eb7a165ebf0b20aedce5ae6b79729e Mon Sep 17 00:00:00 2001 From: Minkra <@> Date: Mon, 20 Nov 2023 17:12:31 +0100 Subject: [PATCH] 29. Aban --- Gerade.java | 11 ++++++++++- Person.java | 7 +++++++ Punkt.java | 4 ++++ Schueler.java | 7 +++++++ Test.java | 18 ++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Person.java create mode 100644 Schueler.java create mode 100644 Test.java diff --git a/Gerade.java b/Gerade.java index 1bfc808..9355a73 100644 --- a/Gerade.java +++ b/Gerade.java @@ -12,6 +12,15 @@ public class Gerade public Gerade( Punkt p1, Punkt p2) { m = (p2.y -p1.y) / (p2.x - p1.x); - c = p1.y - m* p1.x; + c = p1.y - m * p1.x; + } + public Punkt schneide(Gerade g2){ + double x = (g2.c - c) / (m - g2.m); + + double y = m * x + c; + return new Punkt(x, y); + } + public String toString() { + return "y = " + m + " * x + " + c; } } diff --git a/Person.java b/Person.java new file mode 100644 index 0000000..31a47b2 --- /dev/null +++ b/Person.java @@ -0,0 +1,7 @@ + + +public class Person +{ + String vorname; + String nachname; +} diff --git a/Punkt.java b/Punkt.java index b5eba20..db5ce01 100644 --- a/Punkt.java +++ b/Punkt.java @@ -8,4 +8,8 @@ public class Punkt x = _x; y = _y; } + public String toString() { + return "(" + x + "| " + y + " )"; + + } } diff --git a/Schueler.java b/Schueler.java new file mode 100644 index 0000000..f49752d --- /dev/null +++ b/Schueler.java @@ -0,0 +1,7 @@ + + +public class Schueler extends Person +{ + int klasse; + +} diff --git a/Test.java b/Test.java new file mode 100644 index 0000000..33323f5 --- /dev/null +++ b/Test.java @@ -0,0 +1,18 @@ + +public class Test +{ + public static void test() { + Punkt P = new Punkt(1, -1); + Punkt Q = new Punkt(3, 3); + + Gerade g = new Gerade (P, Q); + System.out.println("Gerade g:"); + System.out.println(g); + + Gerade h = new Gerade(-0.5, 2); + + Punkt S = g.schneide(h); + System.out.println("Schnittpunkt:"); + System.out.println(S); + } +}