From 0a8944456b66b00f732b67558772fc3462b0ce79 Mon Sep 17 00:00:00 2001 From: Mario Benov Date: Tue, 5 Nov 2024 23:57:43 +0200 Subject: [PATCH] 11b - inheritance and Object --- .../11b/2024-11-04-object-class/.gitignore | 29 ++++++++++++ .../2024-11-04-object-class/.idea/.gitignore | 3 ++ .../2024-11-04-object-class/.idea/misc.xml | 6 +++ .../2024-11-04-object-class/.idea/modules.xml | 8 ++++ .../11b/2024-11-04-object-class/.idea/vcs.xml | 6 +++ .../2024-11-04-object-class.iml | 11 +++++ .../11b/2024-11-04-object-class/src/Main.java | 44 +++++++++++++++++++ .../2024-11-04-object-class/src/Pastry.java | 42 ++++++++++++++++++ 8 files changed, 149 insertions(+) create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/.gitignore create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/.idea/.gitignore create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/.idea/misc.xml create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/.idea/modules.xml create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/.idea/vcs.xml create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/2024-11-04-object-class.iml create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/src/Main.java create mode 100644 materials/2024-2025/11b/2024-11-04-object-class/src/Pastry.java diff --git a/materials/2024-2025/11b/2024-11-04-object-class/.gitignore b/materials/2024-2025/11b/2024-11-04-object-class/.gitignore new file mode 100644 index 00000000..f68d1099 --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/materials/2024-2025/11b/2024-11-04-object-class/.idea/.gitignore b/materials/2024-2025/11b/2024-11-04-object-class/.idea/.gitignore new file mode 100644 index 00000000..eaf91e2a --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/materials/2024-2025/11b/2024-11-04-object-class/.idea/misc.xml b/materials/2024-2025/11b/2024-11-04-object-class/.idea/misc.xml new file mode 100644 index 00000000..396b4090 --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/2024-11-04-object-class/.idea/modules.xml b/materials/2024-2025/11b/2024-11-04-object-class/.idea/modules.xml new file mode 100644 index 00000000..c4f2b1e2 --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/2024-11-04-object-class/.idea/vcs.xml b/materials/2024-2025/11b/2024-11-04-object-class/.idea/vcs.xml new file mode 100644 index 00000000..15b5e29f --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/2024-11-04-object-class/2024-11-04-object-class.iml b/materials/2024-2025/11b/2024-11-04-object-class/2024-11-04-object-class.iml new file mode 100644 index 00000000..9465dd86 --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/2024-11-04-object-class.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/materials/2024-2025/11b/2024-11-04-object-class/src/Main.java b/materials/2024-2025/11b/2024-11-04-object-class/src/Main.java new file mode 100644 index 00000000..f01cfd77 --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/src/Main.java @@ -0,0 +1,44 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +public class Main { + public static void main(String[] args) { + Object o1 = new Object(); + Object o2 = new Object(); + + System.out.println(o1); + System.out.println(o2); + System.out.println(o1 == o2); + System.out.println(o1.equals(o2)); + System.out.println(o1.toString()); + + Pastry p1 = new Pastry("Prava", false); + Pastry p2 = new Pastry("Sofiiska", true); + Pastry p3 = new Pastry("Prava", false); + + System.out.println(p1); + System.out.println(p2); + System.out.println(p1 == p2); + System.out.println(p1.equals(p2)); + System.out.println(p1.hashCode()); + System.out.println(p2.hashCode()); + + System.out.println(p1 == p3); + System.out.println(p1.equals(p3)); + + Map map1 = new HashMap<>(); + map1.put(p1, p1); + map1.put(p2, p2); + map1.put(p3, p3); + System.out.println(map1); + System.out.println(map1.keySet()); + + Map map2 = new TreeMap<>(); + map2.put(p1, p1); + map2.put(p2, p2); + map2.put(p3, p3); + System.out.println(map2); + System.out.println(map2.keySet()); + } +} \ No newline at end of file diff --git a/materials/2024-2025/11b/2024-11-04-object-class/src/Pastry.java b/materials/2024-2025/11b/2024-11-04-object-class/src/Pastry.java new file mode 100644 index 00000000..783a6a1a --- /dev/null +++ b/materials/2024-2025/11b/2024-11-04-object-class/src/Pastry.java @@ -0,0 +1,42 @@ +import java.util.Objects; + +public class Pastry { + private String name; + private boolean hasCheese; + + public Pastry(String name, boolean hasCheese) { + this.name = name; + this.hasCheese = hasCheese; + } + + public String getName() { + return name; + } + + public boolean getHasCheese() { + return hasCheese; + } + + @Override + public String toString() { + return "Pastry{" + + "name='" + name + '\'' + + ", hasCheese=" + hasCheese + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Pastry pastry = (Pastry) o; + return hasCheese == pastry.hasCheese && +// Objects.equals(name, pastry.name); + name.equals(pastry.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, hasCheese); + } +}