summaryrefslogtreecommitdiff
path: root/Year_2/SE
diff options
context:
space:
mode:
Diffstat (limited to 'Year_2/SE')
-rw-r--r--Year_2/SE/L21_ex2/Main.java11
-rw-r--r--Year_2/SE/design_patterns/singleton/Logs.java10
-rw-r--r--Year_2/SE/design_patterns/singleton/Main.java12
-rw-r--r--Year_2/SE/error_inheritance/Main.java19
-rw-r--r--Year_2/SE/error_inheritance/Person.java10
-rw-r--r--Year_2/SE/error_inheritance/Student.java13
6 files changed, 75 insertions, 0 deletions
diff --git a/Year_2/SE/L21_ex2/Main.java b/Year_2/SE/L21_ex2/Main.java
new file mode 100644
index 0000000..6f077f9
--- /dev/null
+++ b/Year_2/SE/L21_ex2/Main.java
@@ -0,0 +1,11 @@
+import java.util.List;
+
+public class Main {
+ public static void main(String[] args) {
+ List<String> l = List.of("to", "speak", "the", "truth", "and", "pay", "your", "debts");
+ l.stream()
+ .map(x -> x.charAt(0))
+ .forEach(c -> System.out.print(c));
+ }
+}
+
diff --git a/Year_2/SE/design_patterns/singleton/Logs.java b/Year_2/SE/design_patterns/singleton/Logs.java
new file mode 100644
index 0000000..85deef9
--- /dev/null
+++ b/Year_2/SE/design_patterns/singleton/Logs.java
@@ -0,0 +1,10 @@
+public class Logs {
+ private static Logs log;
+
+ private Logs(){}
+
+ public static Logs getInstanceLogs() {
+ if(log == null) log = new Logs();
+ return log;
+ }
+}
diff --git a/Year_2/SE/design_patterns/singleton/Main.java b/Year_2/SE/design_patterns/singleton/Main.java
new file mode 100644
index 0000000..5d05cea
--- /dev/null
+++ b/Year_2/SE/design_patterns/singleton/Main.java
@@ -0,0 +1,12 @@
+public class Main {
+ public static void main(String[] args) {
+ Logs l = Logs.getInstanceLogs();
+ Logs l2 = Logs.getInstanceLogs();
+
+ // Prints "true"
+ System.out.println(l == l2);
+
+ // Error, because the constructor is private
+ // Logs l3 = new Logs();
+ }
+}
diff --git a/Year_2/SE/error_inheritance/Main.java b/Year_2/SE/error_inheritance/Main.java
new file mode 100644
index 0000000..206a513
--- /dev/null
+++ b/Year_2/SE/error_inheritance/Main.java
@@ -0,0 +1,19 @@
+public class Main {
+ public static void main(String[] args) {
+ Student s = new Student();
+ s.setName("Santo");
+ s.setMatr("1948");
+
+ s.print();
+
+ Person p = s;
+ // That's not compile
+ // p.setMatr("1949");
+ p.setName("John");
+ p.print();
+
+ // s.name is equals to p.name, so the code below print
+ // Hello, John[...]
+ s.print();
+ }
+}
diff --git a/Year_2/SE/error_inheritance/Person.java b/Year_2/SE/error_inheritance/Person.java
new file mode 100644
index 0000000..2e52d79
--- /dev/null
+++ b/Year_2/SE/error_inheritance/Person.java
@@ -0,0 +1,10 @@
+public class Person {
+ private String name;
+ public void setName(String n) {
+ this.name = n;
+ }
+
+ public void print() {
+ System.out.println("Hello, "+ this.name);
+ }
+}
diff --git a/Year_2/SE/error_inheritance/Student.java b/Year_2/SE/error_inheritance/Student.java
new file mode 100644
index 0000000..1789489
--- /dev/null
+++ b/Year_2/SE/error_inheritance/Student.java
@@ -0,0 +1,13 @@
+public class Student extends Person {
+ private String matr;
+
+ public void setMatr(String m) {
+ this.matr = m;
+ }
+
+ @Override
+ public void print() {
+ super.print();
+ System.out.println("I'm "+ this.matr);
+ }
+}