From 53e70432fe8698055b3d8b0d277bae838b488d2f Mon Sep 17 00:00:00 2001 From: Ivsucram Date: Thu, 17 Oct 2024 11:51:59 +0800 Subject: [PATCH] Tutorial 5 --- NTU-OOP-Tuts.iml | 1 + T2Q1-1/T2Q1-1.iml | 2 +- T2Q1-2/T2Q1-2.iml | 2 +- T2Q1-3/T2Q1-3.iml | 2 +- T2Q1-4/T2Q1-4.iml | 2 +- T2Q1-5/T2Q1-5.iml | 2 +- T2Q1-extra1/T2Q1-extra1.iml | 2 +- T2Q1-extra2/T2Q1-extra2.iml | 2 +- T2Q1-extra3/T2Q1-extra3.iml | 2 +- T2Q2/T2Q2.iml | 2 +- T3Q1-1/T3Q1-1.iml | 2 +- T3Q1-2/T3Q1-2.iml | 2 +- T3Q1-3/T3Q1-3.iml | 2 +- T3Q1-4/T3Q1-4.iml | 2 +- T3Q1-extra1/T3Q1-extra1.iml | 2 +- T3Q2-1/T3Q2-1.iml | 2 +- T3Q2-2/T3Q2-2.iml | 2 +- T3Q2-3/T3Q2-3.iml | 2 +- T3Q2-4/T3Q2-4.iml | 2 +- T5Q1/T5Q1.iml | 11 ++++++++++ T5Q1/src/Main.java | 11 ++++++++++ T5Q2-A-Sol1/T5Q2-A-Sol1.iml | 11 ++++++++++ T5Q2-A-Sol1/src/ClassA.java | 5 +++++ T5Q2-A-Sol1/src/ClassB.java | 5 +++++ T5Q2-A-Sol1/src/ClassC.java | 3 +++ T5Q2-A-Sol1/src/ClassD.java | 5 +++++ T5Q2-A-Sol1/src/ClassE.java | 8 ++++++++ T5Q2-A-Sol1/src/ClassF.java | 5 +++++ T5Q2-A-Sol1/src/ClassG.java | 5 +++++ T5Q2-A-Sol1/src/Main.java | 5 +++++ T5Q2-A-Sol2/T5Q2-A-Sol2.iml | 11 ++++++++++ T5Q2-A-Sol2/src/ClassA.java | 5 +++++ T5Q2-A-Sol2/src/ClassB.java | 5 +++++ T5Q2-A-Sol2/src/ClassC.java | 3 +++ T5Q2-A-Sol2/src/ClassD.java | 5 +++++ T5Q2-A-Sol2/src/ClassE.java | 6 ++++++ T5Q2-A-Sol2/src/ClassF.java | 8 ++++++++ T5Q2-A-Sol2/src/ClassG.java | 8 ++++++++ T5Q2-A-Sol2/src/Main.java | 5 +++++ T5Q2-A/T5Q2-A.iml | 11 ++++++++++ T5Q2-A/src/ClassA.java | 5 +++++ T5Q2-A/src/ClassB.java | 5 +++++ T5Q2-A/src/ClassC.java | 3 +++ T5Q2-A/src/ClassD.java | 5 +++++ T5Q2-A/src/ClassE.java | 5 +++++ T5Q2-A/src/ClassF.java | 5 +++++ T5Q2-A/src/ClassG.java | 5 +++++ T5Q2-A/src/Main.java | 5 +++++ T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml | 11 ++++++++++ T5Q2-B-FromSol1/src/ClassA.java | 5 +++++ T5Q2-B-FromSol1/src/ClassB.java | 5 +++++ T5Q2-B-FromSol1/src/ClassC.java | 3 +++ T5Q2-B-FromSol1/src/ClassD.java | 5 +++++ T5Q2-B-FromSol1/src/ClassE.java | 8 ++++++++ T5Q2-B-FromSol1/src/ClassF.java | 5 +++++ T5Q2-B-FromSol1/src/ClassG.java | 5 +++++ T5Q2-B-FromSol1/src/Main.java | 15 ++++++++++++++ T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml | 11 ++++++++++ T5Q2-B-FromSol2/src/ClassA.java | 5 +++++ T5Q2-B-FromSol2/src/ClassB.java | 5 +++++ T5Q2-B-FromSol2/src/ClassC.java | 3 +++ T5Q2-B-FromSol2/src/ClassD.java | 5 +++++ T5Q2-B-FromSol2/src/ClassE.java | 6 ++++++ T5Q2-B-FromSol2/src/ClassF.java | 8 ++++++++ T5Q2-B-FromSol2/src/ClassG.java | 8 ++++++++ T5Q2-B-FromSol2/src/Main.java | 15 ++++++++++++++ T5Q2-C/T5Q2-C.iml | 11 ++++++++++ T5Q2-C/src/ClassA.java | 5 +++++ T5Q2-C/src/ClassB.java | 5 +++++ T5Q2-C/src/ClassC.java | 5 +++++ T5Q2-C/src/ClassD.java | 5 +++++ T5Q2-C/src/ClassE.java | 5 +++++ T5Q2-C/src/ClassF.java | 5 +++++ T5Q2-C/src/ClassG.java | 5 +++++ T5Q2-C/src/Main.java | 32 +++++++++++++++++++++++++++++ T5Q3/T5Q3.iml | 11 ++++++++++ T5Q3/src/TestPolygon.java | 10 --------- 77 files changed, 415 insertions(+), 28 deletions(-) create mode 100644 T5Q1/T5Q1.iml create mode 100644 T5Q1/src/Main.java create mode 100644 T5Q2-A-Sol1/T5Q2-A-Sol1.iml create mode 100644 T5Q2-A-Sol1/src/ClassA.java create mode 100644 T5Q2-A-Sol1/src/ClassB.java create mode 100644 T5Q2-A-Sol1/src/ClassC.java create mode 100644 T5Q2-A-Sol1/src/ClassD.java create mode 100644 T5Q2-A-Sol1/src/ClassE.java create mode 100644 T5Q2-A-Sol1/src/ClassF.java create mode 100644 T5Q2-A-Sol1/src/ClassG.java create mode 100644 T5Q2-A-Sol1/src/Main.java create mode 100644 T5Q2-A-Sol2/T5Q2-A-Sol2.iml create mode 100644 T5Q2-A-Sol2/src/ClassA.java create mode 100644 T5Q2-A-Sol2/src/ClassB.java create mode 100644 T5Q2-A-Sol2/src/ClassC.java create mode 100644 T5Q2-A-Sol2/src/ClassD.java create mode 100644 T5Q2-A-Sol2/src/ClassE.java create mode 100644 T5Q2-A-Sol2/src/ClassF.java create mode 100644 T5Q2-A-Sol2/src/ClassG.java create mode 100644 T5Q2-A-Sol2/src/Main.java create mode 100644 T5Q2-A/T5Q2-A.iml create mode 100644 T5Q2-A/src/ClassA.java create mode 100644 T5Q2-A/src/ClassB.java create mode 100644 T5Q2-A/src/ClassC.java create mode 100644 T5Q2-A/src/ClassD.java create mode 100644 T5Q2-A/src/ClassE.java create mode 100644 T5Q2-A/src/ClassF.java create mode 100644 T5Q2-A/src/ClassG.java create mode 100644 T5Q2-A/src/Main.java create mode 100644 T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml create mode 100644 T5Q2-B-FromSol1/src/ClassA.java create mode 100644 T5Q2-B-FromSol1/src/ClassB.java create mode 100644 T5Q2-B-FromSol1/src/ClassC.java create mode 100644 T5Q2-B-FromSol1/src/ClassD.java create mode 100644 T5Q2-B-FromSol1/src/ClassE.java create mode 100644 T5Q2-B-FromSol1/src/ClassF.java create mode 100644 T5Q2-B-FromSol1/src/ClassG.java create mode 100644 T5Q2-B-FromSol1/src/Main.java create mode 100644 T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml create mode 100644 T5Q2-B-FromSol2/src/ClassA.java create mode 100644 T5Q2-B-FromSol2/src/ClassB.java create mode 100644 T5Q2-B-FromSol2/src/ClassC.java create mode 100644 T5Q2-B-FromSol2/src/ClassD.java create mode 100644 T5Q2-B-FromSol2/src/ClassE.java create mode 100644 T5Q2-B-FromSol2/src/ClassF.java create mode 100644 T5Q2-B-FromSol2/src/ClassG.java create mode 100644 T5Q2-B-FromSol2/src/Main.java create mode 100644 T5Q2-C/T5Q2-C.iml create mode 100644 T5Q2-C/src/ClassA.java create mode 100644 T5Q2-C/src/ClassB.java create mode 100644 T5Q2-C/src/ClassC.java create mode 100644 T5Q2-C/src/ClassD.java create mode 100644 T5Q2-C/src/ClassE.java create mode 100644 T5Q2-C/src/ClassF.java create mode 100644 T5Q2-C/src/ClassG.java create mode 100644 T5Q2-C/src/Main.java create mode 100644 T5Q3/T5Q3.iml diff --git a/NTU-OOP-Tuts.iml b/NTU-OOP-Tuts.iml index 9a5cfce..561f220 100644 --- a/NTU-OOP-Tuts.iml +++ b/NTU-OOP-Tuts.iml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/T2Q1-1/T2Q1-1.iml b/T2Q1-1/T2Q1-1.iml index 82236ea..c90834f 100644 --- a/T2Q1-1/T2Q1-1.iml +++ b/T2Q1-1/T2Q1-1.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q1-2/T2Q1-2.iml b/T2Q1-2/T2Q1-2.iml index 82236ea..c90834f 100644 --- a/T2Q1-2/T2Q1-2.iml +++ b/T2Q1-2/T2Q1-2.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q1-3/T2Q1-3.iml b/T2Q1-3/T2Q1-3.iml index 82236ea..c90834f 100644 --- a/T2Q1-3/T2Q1-3.iml +++ b/T2Q1-3/T2Q1-3.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q1-4/T2Q1-4.iml b/T2Q1-4/T2Q1-4.iml index 82236ea..c90834f 100644 --- a/T2Q1-4/T2Q1-4.iml +++ b/T2Q1-4/T2Q1-4.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q1-5/T2Q1-5.iml b/T2Q1-5/T2Q1-5.iml index 82236ea..c90834f 100644 --- a/T2Q1-5/T2Q1-5.iml +++ b/T2Q1-5/T2Q1-5.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q1-extra1/T2Q1-extra1.iml b/T2Q1-extra1/T2Q1-extra1.iml index 82236ea..c90834f 100644 --- a/T2Q1-extra1/T2Q1-extra1.iml +++ b/T2Q1-extra1/T2Q1-extra1.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q1-extra2/T2Q1-extra2.iml b/T2Q1-extra2/T2Q1-extra2.iml index 82236ea..c90834f 100644 --- a/T2Q1-extra2/T2Q1-extra2.iml +++ b/T2Q1-extra2/T2Q1-extra2.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q1-extra3/T2Q1-extra3.iml b/T2Q1-extra3/T2Q1-extra3.iml index 82236ea..c90834f 100644 --- a/T2Q1-extra3/T2Q1-extra3.iml +++ b/T2Q1-extra3/T2Q1-extra3.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T2Q2/T2Q2.iml b/T2Q2/T2Q2.iml index 82236ea..c90834f 100644 --- a/T2Q2/T2Q2.iml +++ b/T2Q2/T2Q2.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q1-1/T3Q1-1.iml b/T3Q1-1/T3Q1-1.iml index 82236ea..c90834f 100644 --- a/T3Q1-1/T3Q1-1.iml +++ b/T3Q1-1/T3Q1-1.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q1-2/T3Q1-2.iml b/T3Q1-2/T3Q1-2.iml index 82236ea..c90834f 100644 --- a/T3Q1-2/T3Q1-2.iml +++ b/T3Q1-2/T3Q1-2.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q1-3/T3Q1-3.iml b/T3Q1-3/T3Q1-3.iml index 82236ea..c90834f 100644 --- a/T3Q1-3/T3Q1-3.iml +++ b/T3Q1-3/T3Q1-3.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q1-4/T3Q1-4.iml b/T3Q1-4/T3Q1-4.iml index 82236ea..c90834f 100644 --- a/T3Q1-4/T3Q1-4.iml +++ b/T3Q1-4/T3Q1-4.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q1-extra1/T3Q1-extra1.iml b/T3Q1-extra1/T3Q1-extra1.iml index 82236ea..c90834f 100644 --- a/T3Q1-extra1/T3Q1-extra1.iml +++ b/T3Q1-extra1/T3Q1-extra1.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q2-1/T3Q2-1.iml b/T3Q2-1/T3Q2-1.iml index 82236ea..c90834f 100644 --- a/T3Q2-1/T3Q2-1.iml +++ b/T3Q2-1/T3Q2-1.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q2-2/T3Q2-2.iml b/T3Q2-2/T3Q2-2.iml index 82236ea..c90834f 100644 --- a/T3Q2-2/T3Q2-2.iml +++ b/T3Q2-2/T3Q2-2.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q2-3/T3Q2-3.iml b/T3Q2-3/T3Q2-3.iml index 82236ea..c90834f 100644 --- a/T3Q2-3/T3Q2-3.iml +++ b/T3Q2-3/T3Q2-3.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T3Q2-4/T3Q2-4.iml b/T3Q2-4/T3Q2-4.iml index 82236ea..c90834f 100644 --- a/T3Q2-4/T3Q2-4.iml +++ b/T3Q2-4/T3Q2-4.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/T5Q1/T5Q1.iml b/T5Q1/T5Q1.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/T5Q1/T5Q1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q1/src/Main.java b/T5Q1/src/Main.java new file mode 100644 index 0000000..79c079f --- /dev/null +++ b/T5Q1/src/Main.java @@ -0,0 +1,11 @@ +public class Main { + public static void main(String[] args) { + ClassF z = new ClassF(); + + z.print(9); + z.print(2, "Cx2002"); + z.print("Object"); + z.print("OODP", "Java"); +// z.print("OODP", 2002); // Compilation error + } +} \ No newline at end of file diff --git a/T5Q2-A-Sol1/T5Q2-A-Sol1.iml b/T5Q2-A-Sol1/T5Q2-A-Sol1.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/T5Q2-A-Sol1/T5Q2-A-Sol1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q2-A-Sol1/src/ClassA.java b/T5Q2-A-Sol1/src/ClassA.java new file mode 100644 index 0000000..afa22fa --- /dev/null +++ b/T5Q2-A-Sol1/src/ClassA.java @@ -0,0 +1,5 @@ +public class ClassA { + public void print(int x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-A-Sol1/src/ClassB.java b/T5Q2-A-Sol1/src/ClassB.java new file mode 100644 index 0000000..fcdb0c3 --- /dev/null +++ b/T5Q2-A-Sol1/src/ClassB.java @@ -0,0 +1,5 @@ +public class ClassB extends ClassA { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-A-Sol1/src/ClassC.java b/T5Q2-A-Sol1/src/ClassC.java new file mode 100644 index 0000000..e1107e2 --- /dev/null +++ b/T5Q2-A-Sol1/src/ClassC.java @@ -0,0 +1,3 @@ +public abstract class ClassC extends ClassA { + public abstract void print(String x, String y); +} diff --git a/T5Q2-A-Sol1/src/ClassD.java b/T5Q2-A-Sol1/src/ClassD.java new file mode 100644 index 0000000..6434f18 --- /dev/null +++ b/T5Q2-A-Sol1/src/ClassD.java @@ -0,0 +1,5 @@ +public class ClassD extends ClassC { + public void print(String a, String b) { + System.out.println(a + " " + b); + } +} diff --git a/T5Q2-A-Sol1/src/ClassE.java b/T5Q2-A-Sol1/src/ClassE.java new file mode 100644 index 0000000..7a8da05 --- /dev/null +++ b/T5Q2-A-Sol1/src/ClassE.java @@ -0,0 +1,8 @@ +public class ClassE extends ClassC { + public void print(String x) { + System.out.println(x); + } + public void print(String x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-A-Sol1/src/ClassF.java b/T5Q2-A-Sol1/src/ClassF.java new file mode 100644 index 0000000..cd9a8dc --- /dev/null +++ b/T5Q2-A-Sol1/src/ClassF.java @@ -0,0 +1,5 @@ +public class ClassF extends ClassE { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-A-Sol1/src/ClassG.java b/T5Q2-A-Sol1/src/ClassG.java new file mode 100644 index 0000000..54221cc --- /dev/null +++ b/T5Q2-A-Sol1/src/ClassG.java @@ -0,0 +1,5 @@ +public class ClassG extends ClassF { + public void print(String x) { + System.out.println(x); + } +} diff --git a/T5Q2-A-Sol1/src/Main.java b/T5Q2-A-Sol1/src/Main.java new file mode 100644 index 0000000..be9bb2d --- /dev/null +++ b/T5Q2-A-Sol1/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + ClassF z = new ClassF(); + } +} \ No newline at end of file diff --git a/T5Q2-A-Sol2/T5Q2-A-Sol2.iml b/T5Q2-A-Sol2/T5Q2-A-Sol2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/T5Q2-A-Sol2/T5Q2-A-Sol2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q2-A-Sol2/src/ClassA.java b/T5Q2-A-Sol2/src/ClassA.java new file mode 100644 index 0000000..afa22fa --- /dev/null +++ b/T5Q2-A-Sol2/src/ClassA.java @@ -0,0 +1,5 @@ +public class ClassA { + public void print(int x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-A-Sol2/src/ClassB.java b/T5Q2-A-Sol2/src/ClassB.java new file mode 100644 index 0000000..fcdb0c3 --- /dev/null +++ b/T5Q2-A-Sol2/src/ClassB.java @@ -0,0 +1,5 @@ +public class ClassB extends ClassA { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-A-Sol2/src/ClassC.java b/T5Q2-A-Sol2/src/ClassC.java new file mode 100644 index 0000000..e1107e2 --- /dev/null +++ b/T5Q2-A-Sol2/src/ClassC.java @@ -0,0 +1,3 @@ +public abstract class ClassC extends ClassA { + public abstract void print(String x, String y); +} diff --git a/T5Q2-A-Sol2/src/ClassD.java b/T5Q2-A-Sol2/src/ClassD.java new file mode 100644 index 0000000..6434f18 --- /dev/null +++ b/T5Q2-A-Sol2/src/ClassD.java @@ -0,0 +1,5 @@ +public class ClassD extends ClassC { + public void print(String a, String b) { + System.out.println(a + " " + b); + } +} diff --git a/T5Q2-A-Sol2/src/ClassE.java b/T5Q2-A-Sol2/src/ClassE.java new file mode 100644 index 0000000..baba39b --- /dev/null +++ b/T5Q2-A-Sol2/src/ClassE.java @@ -0,0 +1,6 @@ +public abstract class ClassE extends ClassC { + public void print(String x) { + System.out.println(x); + } + public abstract void print(String x, String y); +} diff --git a/T5Q2-A-Sol2/src/ClassF.java b/T5Q2-A-Sol2/src/ClassF.java new file mode 100644 index 0000000..1cd9000 --- /dev/null +++ b/T5Q2-A-Sol2/src/ClassF.java @@ -0,0 +1,8 @@ +public class ClassF extends ClassE { + public void print(int x) { + System.out.println(x); + } + public void print(String x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-A-Sol2/src/ClassG.java b/T5Q2-A-Sol2/src/ClassG.java new file mode 100644 index 0000000..215ba8b --- /dev/null +++ b/T5Q2-A-Sol2/src/ClassG.java @@ -0,0 +1,8 @@ +public class ClassG extends ClassF { + public void print(String x) { + System.out.println(x); + } + public void print(String x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-A-Sol2/src/Main.java b/T5Q2-A-Sol2/src/Main.java new file mode 100644 index 0000000..f5858db --- /dev/null +++ b/T5Q2-A-Sol2/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + + } +} \ No newline at end of file diff --git a/T5Q2-A/T5Q2-A.iml b/T5Q2-A/T5Q2-A.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/T5Q2-A/T5Q2-A.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q2-A/src/ClassA.java b/T5Q2-A/src/ClassA.java new file mode 100644 index 0000000..afa22fa --- /dev/null +++ b/T5Q2-A/src/ClassA.java @@ -0,0 +1,5 @@ +public class ClassA { + public void print(int x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-A/src/ClassB.java b/T5Q2-A/src/ClassB.java new file mode 100644 index 0000000..fcdb0c3 --- /dev/null +++ b/T5Q2-A/src/ClassB.java @@ -0,0 +1,5 @@ +public class ClassB extends ClassA { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-A/src/ClassC.java b/T5Q2-A/src/ClassC.java new file mode 100644 index 0000000..e1107e2 --- /dev/null +++ b/T5Q2-A/src/ClassC.java @@ -0,0 +1,3 @@ +public abstract class ClassC extends ClassA { + public abstract void print(String x, String y); +} diff --git a/T5Q2-A/src/ClassD.java b/T5Q2-A/src/ClassD.java new file mode 100644 index 0000000..6434f18 --- /dev/null +++ b/T5Q2-A/src/ClassD.java @@ -0,0 +1,5 @@ +public class ClassD extends ClassC { + public void print(String a, String b) { + System.out.println(a + " " + b); + } +} diff --git a/T5Q2-A/src/ClassE.java b/T5Q2-A/src/ClassE.java new file mode 100644 index 0000000..89f1391 --- /dev/null +++ b/T5Q2-A/src/ClassE.java @@ -0,0 +1,5 @@ +public class ClassE extends ClassC { + public void print(String x) { + System.out.println(x); + } +} diff --git a/T5Q2-A/src/ClassF.java b/T5Q2-A/src/ClassF.java new file mode 100644 index 0000000..cd9a8dc --- /dev/null +++ b/T5Q2-A/src/ClassF.java @@ -0,0 +1,5 @@ +public class ClassF extends ClassE { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-A/src/ClassG.java b/T5Q2-A/src/ClassG.java new file mode 100644 index 0000000..54221cc --- /dev/null +++ b/T5Q2-A/src/ClassG.java @@ -0,0 +1,5 @@ +public class ClassG extends ClassF { + public void print(String x) { + System.out.println(x); + } +} diff --git a/T5Q2-A/src/Main.java b/T5Q2-A/src/Main.java new file mode 100644 index 0000000..be9bb2d --- /dev/null +++ b/T5Q2-A/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + ClassF z = new ClassF(); + } +} \ No newline at end of file diff --git a/T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml b/T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml new file mode 100644 index 0000000..82236ea --- /dev/null +++ b/T5Q2-B-FromSol1/T5Q2-B-FromSol1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q2-B-FromSol1/src/ClassA.java b/T5Q2-B-FromSol1/src/ClassA.java new file mode 100644 index 0000000..afa22fa --- /dev/null +++ b/T5Q2-B-FromSol1/src/ClassA.java @@ -0,0 +1,5 @@ +public class ClassA { + public void print(int x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-B-FromSol1/src/ClassB.java b/T5Q2-B-FromSol1/src/ClassB.java new file mode 100644 index 0000000..fcdb0c3 --- /dev/null +++ b/T5Q2-B-FromSol1/src/ClassB.java @@ -0,0 +1,5 @@ +public class ClassB extends ClassA { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-B-FromSol1/src/ClassC.java b/T5Q2-B-FromSol1/src/ClassC.java new file mode 100644 index 0000000..e1107e2 --- /dev/null +++ b/T5Q2-B-FromSol1/src/ClassC.java @@ -0,0 +1,3 @@ +public abstract class ClassC extends ClassA { + public abstract void print(String x, String y); +} diff --git a/T5Q2-B-FromSol1/src/ClassD.java b/T5Q2-B-FromSol1/src/ClassD.java new file mode 100644 index 0000000..6434f18 --- /dev/null +++ b/T5Q2-B-FromSol1/src/ClassD.java @@ -0,0 +1,5 @@ +public class ClassD extends ClassC { + public void print(String a, String b) { + System.out.println(a + " " + b); + } +} diff --git a/T5Q2-B-FromSol1/src/ClassE.java b/T5Q2-B-FromSol1/src/ClassE.java new file mode 100644 index 0000000..7a8da05 --- /dev/null +++ b/T5Q2-B-FromSol1/src/ClassE.java @@ -0,0 +1,8 @@ +public class ClassE extends ClassC { + public void print(String x) { + System.out.println(x); + } + public void print(String x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-B-FromSol1/src/ClassF.java b/T5Q2-B-FromSol1/src/ClassF.java new file mode 100644 index 0000000..cd9a8dc --- /dev/null +++ b/T5Q2-B-FromSol1/src/ClassF.java @@ -0,0 +1,5 @@ +public class ClassF extends ClassE { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-B-FromSol1/src/ClassG.java b/T5Q2-B-FromSol1/src/ClassG.java new file mode 100644 index 0000000..54221cc --- /dev/null +++ b/T5Q2-B-FromSol1/src/ClassG.java @@ -0,0 +1,5 @@ +public class ClassG extends ClassF { + public void print(String x) { + System.out.println(x); + } +} diff --git a/T5Q2-B-FromSol1/src/Main.java b/T5Q2-B-FromSol1/src/Main.java new file mode 100644 index 0000000..42980ef --- /dev/null +++ b/T5Q2-B-FromSol1/src/Main.java @@ -0,0 +1,15 @@ +public class Main { + public static void main(String[] args) { + // I - Works +// ClassC c = new ClassD(); +// c.print("hello", "there"); + + // II - Does not compile because class C is abstract +// ClassA a = new ClassC(); +// a.print(1, "there"); + + // III - Doesn't work - Class A does not have print(string, string) method +// ClassA a = new ClassF(); +// a.print("hello", "there"); + } +} \ No newline at end of file diff --git a/T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml b/T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml new file mode 100644 index 0000000..82236ea --- /dev/null +++ b/T5Q2-B-FromSol2/T5Q2-B-FromSol2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q2-B-FromSol2/src/ClassA.java b/T5Q2-B-FromSol2/src/ClassA.java new file mode 100644 index 0000000..afa22fa --- /dev/null +++ b/T5Q2-B-FromSol2/src/ClassA.java @@ -0,0 +1,5 @@ +public class ClassA { + public void print(int x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-B-FromSol2/src/ClassB.java b/T5Q2-B-FromSol2/src/ClassB.java new file mode 100644 index 0000000..fcdb0c3 --- /dev/null +++ b/T5Q2-B-FromSol2/src/ClassB.java @@ -0,0 +1,5 @@ +public class ClassB extends ClassA { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-B-FromSol2/src/ClassC.java b/T5Q2-B-FromSol2/src/ClassC.java new file mode 100644 index 0000000..e1107e2 --- /dev/null +++ b/T5Q2-B-FromSol2/src/ClassC.java @@ -0,0 +1,3 @@ +public abstract class ClassC extends ClassA { + public abstract void print(String x, String y); +} diff --git a/T5Q2-B-FromSol2/src/ClassD.java b/T5Q2-B-FromSol2/src/ClassD.java new file mode 100644 index 0000000..6434f18 --- /dev/null +++ b/T5Q2-B-FromSol2/src/ClassD.java @@ -0,0 +1,5 @@ +public class ClassD extends ClassC { + public void print(String a, String b) { + System.out.println(a + " " + b); + } +} diff --git a/T5Q2-B-FromSol2/src/ClassE.java b/T5Q2-B-FromSol2/src/ClassE.java new file mode 100644 index 0000000..baba39b --- /dev/null +++ b/T5Q2-B-FromSol2/src/ClassE.java @@ -0,0 +1,6 @@ +public abstract class ClassE extends ClassC { + public void print(String x) { + System.out.println(x); + } + public abstract void print(String x, String y); +} diff --git a/T5Q2-B-FromSol2/src/ClassF.java b/T5Q2-B-FromSol2/src/ClassF.java new file mode 100644 index 0000000..1cd9000 --- /dev/null +++ b/T5Q2-B-FromSol2/src/ClassF.java @@ -0,0 +1,8 @@ +public class ClassF extends ClassE { + public void print(int x) { + System.out.println(x); + } + public void print(String x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-B-FromSol2/src/ClassG.java b/T5Q2-B-FromSol2/src/ClassG.java new file mode 100644 index 0000000..215ba8b --- /dev/null +++ b/T5Q2-B-FromSol2/src/ClassG.java @@ -0,0 +1,8 @@ +public class ClassG extends ClassF { + public void print(String x) { + System.out.println(x); + } + public void print(String x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-B-FromSol2/src/Main.java b/T5Q2-B-FromSol2/src/Main.java new file mode 100644 index 0000000..5380632 --- /dev/null +++ b/T5Q2-B-FromSol2/src/Main.java @@ -0,0 +1,15 @@ +public class Main { + public static void main(String[] args) { + // I - Works + ClassC c = new ClassD(); + c.print("hello", "there"); + + // II - Does not compile because class C is abstract +// ClassA a = new ClassC(); +// a.print(1, "there") + + // III - Works + ClassF a = new ClassF(); + a.print("hello", "there"); + } +} \ No newline at end of file diff --git a/T5Q2-C/T5Q2-C.iml b/T5Q2-C/T5Q2-C.iml new file mode 100644 index 0000000..82236ea --- /dev/null +++ b/T5Q2-C/T5Q2-C.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q2-C/src/ClassA.java b/T5Q2-C/src/ClassA.java new file mode 100644 index 0000000..afa22fa --- /dev/null +++ b/T5Q2-C/src/ClassA.java @@ -0,0 +1,5 @@ +public class ClassA { + public void print(int x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-C/src/ClassB.java b/T5Q2-C/src/ClassB.java new file mode 100644 index 0000000..fcdb0c3 --- /dev/null +++ b/T5Q2-C/src/ClassB.java @@ -0,0 +1,5 @@ +public class ClassB extends ClassA { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-C/src/ClassC.java b/T5Q2-C/src/ClassC.java new file mode 100644 index 0000000..a1fdca0 --- /dev/null +++ b/T5Q2-C/src/ClassC.java @@ -0,0 +1,5 @@ +public class ClassC extends ClassA { + public void print(String x, String y) { + System.out.println(x + " " + y); + } +} diff --git a/T5Q2-C/src/ClassD.java b/T5Q2-C/src/ClassD.java new file mode 100644 index 0000000..6434f18 --- /dev/null +++ b/T5Q2-C/src/ClassD.java @@ -0,0 +1,5 @@ +public class ClassD extends ClassC { + public void print(String a, String b) { + System.out.println(a + " " + b); + } +} diff --git a/T5Q2-C/src/ClassE.java b/T5Q2-C/src/ClassE.java new file mode 100644 index 0000000..89f1391 --- /dev/null +++ b/T5Q2-C/src/ClassE.java @@ -0,0 +1,5 @@ +public class ClassE extends ClassC { + public void print(String x) { + System.out.println(x); + } +} diff --git a/T5Q2-C/src/ClassF.java b/T5Q2-C/src/ClassF.java new file mode 100644 index 0000000..cd9a8dc --- /dev/null +++ b/T5Q2-C/src/ClassF.java @@ -0,0 +1,5 @@ +public class ClassF extends ClassE { + public void print(int x) { + System.out.println(x); + } +} diff --git a/T5Q2-C/src/ClassG.java b/T5Q2-C/src/ClassG.java new file mode 100644 index 0000000..54221cc --- /dev/null +++ b/T5Q2-C/src/ClassG.java @@ -0,0 +1,5 @@ +public class ClassG extends ClassF { + public void print(String x) { + System.out.println(x); + } +} diff --git a/T5Q2-C/src/Main.java b/T5Q2-C/src/Main.java new file mode 100644 index 0000000..8b15fce --- /dev/null +++ b/T5Q2-C/src/Main.java @@ -0,0 +1,32 @@ +public class Main { + public static void main(String[] args) { + // I - Doesn't work because downcast needs to be explicitly declared +// ClassC c = new ClassD(); +// ClassE e = c; +// ClassE e = (ClassE) c; + + // II - CanĀ“t upcast because they are from different family branches +// ClassB b = new ClassE(); +// b.print("hello"); + + // III +// ClassA a = new ClassF(); // Ok +// a.print(12, "there"); // Ok +// a.print(88); // Compilation error + + // IV +// ClassA a = new ClassC(); // Ok +// ClassG g = new (ClassG)a; // Syntax error +// g.print("hello"); // RunTime error: trick + + // V +// ClassA a = new ClassC(); // ok +// ClassG g = (ClassG)a; // ok +// g.print("hello", "there"); // Runtime error: trick + + // VI +// ClassA a = new ClassF(); // OK +// ClassC f = (ClassC)a; // Ok +// f.print(88, "there"); // Ok + } +} \ No newline at end of file diff --git a/T5Q3/T5Q3.iml b/T5Q3/T5Q3.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/T5Q3/T5Q3.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T5Q3/src/TestPolygon.java b/T5Q3/src/TestPolygon.java index a153d31..2f34292 100644 --- a/T5Q3/src/TestPolygon.java +++ b/T5Q3/src/TestPolygon.java @@ -29,16 +29,6 @@ public class TestPolygon { - - - - - - - - - -