From a818828950b7afde8d7a334b088026bc2b1a562f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sat, 6 Jan 2024 23:41:23 +0100 Subject: DN09 --- "\305\241ola/p1/dn/9/Kaca.java" | 1 + "\305\241ola/p1/dn/9/Lev.java" | 1 + "\305\241ola/p1/dn/9/Macka.java" | 1 + "\305\241ola/p1/dn/9/Medved.java" | 1 + "\305\241ola/p1/dn/9/Plazilec.java" | 1 + "\305\241ola/p1/dn/9/Preganjanje.java" | 25 +++++++++++++++++++++++++ "\305\241ola/p1/dn/9/Sesalec.java" | 1 + "\305\241ola/p1/dn/9/Shramba.java" | 22 ++++++++++++++++++++++ "\305\241ola/p1/dn/9/Test.java" | 19 +++++++++++++++++++ "\305\241ola/p1/dn/9/Tiger.java" | 1 + "\305\241ola/p1/dn/9/Zelva.java" | 1 + "\305\241ola/p1/dn/9/Zival.java" | 1 + "\305\241ola/p1/dn/9/ZivalImplementacija.java" | 21 +++++++++++++++++++++ 13 files changed, 96 insertions(+) create mode 100644 "\305\241ola/p1/dn/9/Kaca.java" create mode 100644 "\305\241ola/p1/dn/9/Lev.java" create mode 100644 "\305\241ola/p1/dn/9/Macka.java" create mode 100644 "\305\241ola/p1/dn/9/Medved.java" create mode 100644 "\305\241ola/p1/dn/9/Plazilec.java" create mode 100644 "\305\241ola/p1/dn/9/Preganjanje.java" create mode 100644 "\305\241ola/p1/dn/9/Sesalec.java" create mode 100644 "\305\241ola/p1/dn/9/Shramba.java" create mode 100644 "\305\241ola/p1/dn/9/Test.java" create mode 100644 "\305\241ola/p1/dn/9/Tiger.java" create mode 100644 "\305\241ola/p1/dn/9/Zelva.java" create mode 100644 "\305\241ola/p1/dn/9/Zival.java" create mode 100644 "\305\241ola/p1/dn/9/ZivalImplementacija.java" diff --git "a/\305\241ola/p1/dn/9/Kaca.java" "b/\305\241ola/p1/dn/9/Kaca.java" new file mode 100644 index 0000000..114f3b4 --- /dev/null +++ "b/\305\241ola/p1/dn/9/Kaca.java" @@ -0,0 +1 @@ +public class Kaca extends Plazilec {} diff --git "a/\305\241ola/p1/dn/9/Lev.java" "b/\305\241ola/p1/dn/9/Lev.java" new file mode 100644 index 0000000..f593344 --- /dev/null +++ "b/\305\241ola/p1/dn/9/Lev.java" @@ -0,0 +1 @@ +public class Lev extends Macka {} diff --git "a/\305\241ola/p1/dn/9/Macka.java" "b/\305\241ola/p1/dn/9/Macka.java" new file mode 100644 index 0000000..ae23486 --- /dev/null +++ "b/\305\241ola/p1/dn/9/Macka.java" @@ -0,0 +1 @@ +public class Macka extends Sesalec {} diff --git "a/\305\241ola/p1/dn/9/Medved.java" "b/\305\241ola/p1/dn/9/Medved.java" new file mode 100644 index 0000000..20515ba --- /dev/null +++ "b/\305\241ola/p1/dn/9/Medved.java" @@ -0,0 +1 @@ +public class Medved extends Sesalec {} diff --git "a/\305\241ola/p1/dn/9/Plazilec.java" "b/\305\241ola/p1/dn/9/Plazilec.java" new file mode 100644 index 0000000..1e46073 --- /dev/null +++ "b/\305\241ola/p1/dn/9/Plazilec.java" @@ -0,0 +1 @@ +public class Plazilec extends Zival {} diff --git "a/\305\241ola/p1/dn/9/Preganjanje.java" "b/\305\241ola/p1/dn/9/Preganjanje.java" new file mode 100644 index 0000000..74485d1 --- /dev/null +++ "b/\305\241ola/p1/dn/9/Preganjanje.java" @@ -0,0 +1,25 @@ +import java.util.*; +public class Preganjanje { + private Class preganjalec; + private Class preganjan; + public Preganjanje (Class preganjalec, Class preganjan) { + this.preganjalec = preganjalec; + this.preganjan = preganjan; + } + public int hashCode () { + return 1; + //return Objects.hash(preganjalec, preganjan); + } + @Override + public boolean equals (Object drugi) { + if (this == drugi) + return true; + if (drugi == null || getClass() != drugi.getClass()) + return false; + Preganjanje drugo = (Preganjanje) drugi; + return preganjalec.equals(drugo.preganjalec) && preganjan.equals(drugo.preganjan); + } + public String toString () { + return String.format("%s->%s", preganjalec.getName(), preganjan.getName()); + } +} diff --git "a/\305\241ola/p1/dn/9/Sesalec.java" "b/\305\241ola/p1/dn/9/Sesalec.java" new file mode 100644 index 0000000..611513c --- /dev/null +++ "b/\305\241ola/p1/dn/9/Sesalec.java" @@ -0,0 +1 @@ +public class Sesalec extends Zival {} diff --git "a/\305\241ola/p1/dn/9/Shramba.java" "b/\305\241ola/p1/dn/9/Shramba.java" new file mode 100644 index 0000000..c212b9c --- /dev/null +++ "b/\305\241ola/p1/dn/9/Shramba.java" @@ -0,0 +1,22 @@ +import java.util.*; +public class Shramba { + static Map, Integer> hranjenja = new HashMap, Integer>(); + public static Map preganjanja = new HashMap(); + public void seHrani () { + for (Class r = this.getClass(); r.getSuperclass() != null; r = r.getSuperclass()) + hranjenja.put(r, hranjenja.getOrDefault(r, 0)+1); + } + public int steviloHranjenj () { + return hranjenja.getOrDefault(this.getClass(), 0); + } + public void preganja (Zival z) { + for (Class s = this.getClass(); s.getSuperclass() != null; s = s.getSuperclass()) + for (Class t = z.getClass(); t.getSuperclass() != null; t = t.getSuperclass()) { + Preganjanje p = new Preganjanje(s, t); + preganjanja.put(p, preganjanja.getOrDefault(p, 0)+1); + } + } + public int steviloPreganjanj (Zival z) { + return preganjanja.getOrDefault(new Preganjanje(this.getClass(), z.getClass()), 0); + } +} diff --git "a/\305\241ola/p1/dn/9/Test.java" "b/\305\241ola/p1/dn/9/Test.java" new file mode 100644 index 0000000..d0a83d4 --- /dev/null +++ "b/\305\241ola/p1/dn/9/Test.java" @@ -0,0 +1,19 @@ +import java.util.*; +public class Test { + public static void main (String[] args) { + Zival z = new Zival(); + Zival z2 = new Zival(); + Sesalec s = new Sesalec(); + Medved m = new Medved(); + Tiger t = new Tiger(); + z.seHrani(); + s.seHrani(); + t.preganja(m); + t.preganja(m); + System.out.println(Arrays.toString(t.preganjanja.entrySet().toArray())); + System.out.println("z: " + z.steviloHranjenj() + " z2: " + z2.steviloHranjenj()); + System.out.println("---"); + System.out.println("t->m: " + t.steviloPreganjanj(m)); + System.out.println("t->m: " + z.steviloPreganjanj(z)); + } +} diff --git "a/\305\241ola/p1/dn/9/Tiger.java" "b/\305\241ola/p1/dn/9/Tiger.java" new file mode 100644 index 0000000..14a70da --- /dev/null +++ "b/\305\241ola/p1/dn/9/Tiger.java" @@ -0,0 +1 @@ +public class Tiger extends Macka {} diff --git "a/\305\241ola/p1/dn/9/Zelva.java" "b/\305\241ola/p1/dn/9/Zelva.java" new file mode 100644 index 0000000..cfb4cde --- /dev/null +++ "b/\305\241ola/p1/dn/9/Zelva.java" @@ -0,0 +1 @@ +public class Zelva extends Plazilec {} diff --git "a/\305\241ola/p1/dn/9/Zival.java" "b/\305\241ola/p1/dn/9/Zival.java" new file mode 100644 index 0000000..5ccfed4 --- /dev/null +++ "b/\305\241ola/p1/dn/9/Zival.java" @@ -0,0 +1 @@ +public class Zival extends Shramba {} diff --git "a/\305\241ola/p1/dn/9/ZivalImplementacija.java" "b/\305\241ola/p1/dn/9/ZivalImplementacija.java" new file mode 100644 index 0000000..c5ba81e --- /dev/null +++ "b/\305\241ola/p1/dn/9/ZivalImplementacija.java" @@ -0,0 +1,21 @@ +// unused +import java.util.*; +public class ZivalImplementacija { + int hranjenj; + List implementacije; + public void dodajImplementacijo (ZivalImplementacija z) { + if (implementacije == null) + implementacije = new ArrayList(); + implementacije.add(z); + } + public void seHrani () { + this.hranjenj++; + } + public int steviloHranjenj () { + int r = hranjenj; + if (implementacije != null) + for (ZivalImplementacija i : implementacije) + r += i.steviloHranjenj(); + return r; + } +} -- cgit v1.2.3