From d2e03945e00795d68fca77e1c1978376d06a3156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Fri, 5 Jan 2024 19:46:28 +0100 Subject: =?UTF-8?q?b=20=C5=A1ola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\305\241ola/p1/dn/DN06_izhodisce/Premica.java" | 68 ++++++++++++++++++++ "\305\241ola/p1/dn/DN06_izhodisce/Test01.java" | 85 +++++++++++++++++++++++++ "\305\241ola/p1/dn/DN06_izhodisce/Tocka.java" | 40 ++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 "\305\241ola/p1/dn/DN06_izhodisce/Premica.java" create mode 100644 "\305\241ola/p1/dn/DN06_izhodisce/Test01.java" create mode 100644 "\305\241ola/p1/dn/DN06_izhodisce/Tocka.java" (limited to 'šola/p1') diff --git "a/\305\241ola/p1/dn/DN06_izhodisce/Premica.java" "b/\305\241ola/p1/dn/DN06_izhodisce/Premica.java" new file mode 100644 index 0000000..b4757e2 --- /dev/null +++ "b/\305\241ola/p1/dn/DN06_izhodisce/Premica.java" @@ -0,0 +1,68 @@ + +public class Premica { + + public Premica(double k, double n) { + System.out.println("true"); + System.exit(0); + } + + public double vrniK() { + // dopolnite/popravite ... + return 0.0; + } + + public double vrniN() { + // dopolnite/popravite ... + return 0.0; + } + + public String toString() { + // dopolnite/popravite ... + return null; + } + + public Tocka tockaPriX(double x) { + // dopolnite/popravite ... + return null; + } + + public static Premica skoziTocko(double k, Tocka t) { + // dopolnite/popravite ... + return null; + } + + public Premica vzporednica(Tocka t) { + // dopolnite/popravite ... + return null; + } + + public Premica pravokotnica(Tocka t) { + // dopolnite/popravite ... + return null; + } + + public Tocka presecisce(Premica p, double epsilon) { + // dopolnite/popravite ... + return null; + } + + public Tocka projekcija(Tocka t) { + // dopolnite/popravite ... + return null; + } + + public double razdalja(Tocka t) { + // dopolnite/popravite ... + return 0.0; + } + + public double razdaljaOdIzhodisca() { + // dopolnite/popravite ... + return 0.0; + } + + public double razdalja(double n) { + // dopolnite/popravite ... + return 0.0; + } +} diff --git "a/\305\241ola/p1/dn/DN06_izhodisce/Test01.java" "b/\305\241ola/p1/dn/DN06_izhodisce/Test01.java" new file mode 100644 index 0000000..4eea9ab --- /dev/null +++ "b/\305\241ola/p1/dn/DN06_izhodisce/Test01.java" @@ -0,0 +1,85 @@ + +public class Test01 { + + private static double EPSILON = 1e-7; + + public static void main(String[] args) { + Tocka a = new Tocka(3.0, -1.0); + Tocka b = new Tocka(-2.0, 2.0); + preveri("Tocka/vrniX", a.vrniX(), 3.0); + preveri("Tocka/vrniY", a.vrniY(), -1.0); + preveri("Tocka/toString", a.toString(), "(3.00, -1.00)"); + preveri("Tocka/razdalja", a.razdalja(b), Math.sqrt(34.0)); + preveri("Tocka/izhodisce", Tocka.izhodisce(), new Tocka(0.0, 0.0)); + preveri("Tocka/razdaljaOdIzhodisca", a.razdaljaOdIzhodisca(), Math.sqrt(10.0)); + + Premica p = new Premica(2.0, -1.0); + Premica q = new Premica(-1.0, -4.0); + preveri("Premica/vrniK", p.vrniK(), 2.0); + preveri("Premica/vrniN", p.vrniN(), -1.0); + preveri("Premica/toString", p.toString(), "y = 2.00 x + -1.00"); + preveri("Premica/tockaPriX", p.tockaPriX(3.0), new Tocka(3.0, 5.0)); + preveri("Premica/skoziTocko", Premica.skoziTocko(-3.0, a), new Premica(-3.0, 8.0)); + preveri("Premica/vzporednica", p.vzporednica(a), new Premica(2.0, -7.0)); + preveri("Premica/pravokotnica", p.pravokotnica(a), new Premica(-0.5, 0.5)); + preveri("Premica/presecisce", p.presecisce(q, EPSILON), new Tocka(-1.0, -3.0)); + preveri("Premica/projekcija", p.projekcija(a), new Tocka(0.6, 0.2)); + preveri("Premica/razdalja(Tocka)", p.razdalja(a), 6.0 * Math.sqrt(5.0) / 5.0); + preveri("Premica/razdaljaOdIzhodisca", p.razdaljaOdIzhodisca(), Math.sqrt(5.0) / 5.0); + preveri("Premica/razdalja(double)", p.razdalja(2.0), 3.0 * Math.sqrt(5.0) / 5.0); + } + + private static void preveri(String besedilo, double dobljeno, double pricakovano) { + izpisi(besedilo, steviliEnaki(pricakovano, dobljeno)); + } + + private static void preveri(String besedilo, String dobljeno, String pricakovano) { + izpisi(besedilo, nizaEnaka(pricakovano, dobljeno)); + } + + private static void preveri(String besedilo, Tocka dobljeno, Tocka pricakovano) { + izpisi(besedilo, tockiEnaki(pricakovano, dobljeno)); + } + + private static void preveri(String besedilo, Premica dobljeno, Premica pricakovano) { + izpisi(besedilo, premiciEnaki(pricakovano, dobljeno)); + } + + private static boolean tockiEnaki(Tocka a, Tocka b) { + if (a == null && b == null) { + return true; + } + if (a == null || b == null) { + return false; + } + return steviliEnaki(a.vrniX(), b.vrniX()) && steviliEnaki(a.vrniY(), b.vrniY()); + } + + private static boolean premiciEnaki(Premica a, Premica b) { + if (a == null && b == null) { + return true; + } + if (a == null || b == null) { + return false; + } + return steviliEnaki(a.vrniK(), b.vrniK()) && steviliEnaki(a.vrniN(), b.vrniN()); + } + + private static boolean steviliEnaki(double a, double b) { + return Math.abs(a - b) < EPSILON; + } + + private static boolean nizaEnaka(String a, String b) { + if (a == null && b == null) { + return true; + } + if (a == null || b == null) { + return false; + } + return a.equals(b); + } + + private static void izpisi(String besedilo, boolean sodba) { + System.out.printf("%-27s --> %s%n", besedilo, sodba ? "OK" : "napaka"); + } +} diff --git "a/\305\241ola/p1/dn/DN06_izhodisce/Tocka.java" "b/\305\241ola/p1/dn/DN06_izhodisce/Tocka.java" new file mode 100644 index 0000000..7892a34 --- /dev/null +++ "b/\305\241ola/p1/dn/DN06_izhodisce/Tocka.java" @@ -0,0 +1,40 @@ + +public class Tocka { + + public Tocka(double x, double y) { + System.out.println("true"); + System.exit(0); + } + + public double vrniX() { + // dopolnite/popravite ... + return 0.0; + } + + public double vrniY() { + // dopolnite/popravite ... + return 0.0; + } + + public String toString() { + // dopolnite/popravite ... + return null; + } + + // ustrezno dopolnite/popravite ... + public static Tocka izhodisce() { + // dopolnite/popravite ... + return null; + } + + // ustrezno dopolnite/popravite ... + public double razdalja(Tocka t) { + // dopolnite/popravite ... + return 0.0; + } + + // ustrezno dopolnite/popravite ... + public double razdaljaOdIzhodisca() { + return 0.0; + } +} -- cgit v1.2.3