Tutorial 5

This commit is contained in:
Marcus Vinicius de Carvalho 2024-10-17 11:51:59 +08:00
parent 1435fb21b9
commit 53e70432fe
77 changed files with 415 additions and 28 deletions

View File

@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
T5Q1/T5Q1.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
T5Q1/src/Main.java Normal file
View File

@ -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
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,5 @@
public class ClassA {
public void print(int x, String y) {
System.out.println(x + " " + y);
}
}

View File

@ -0,0 +1,5 @@
public class ClassB extends ClassA {
public void print(int x) {
System.out.println(x);
}
}

View File

@ -0,0 +1,3 @@
public abstract class ClassC extends ClassA {
public abstract void print(String x, String y);
}

View File

@ -0,0 +1,5 @@
public class ClassD extends ClassC {
public void print(String a, String b) {
System.out.println(a + " " + b);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,5 @@
public class ClassF extends ClassE {
public void print(int x) {
System.out.println(x);
}
}

View File

@ -0,0 +1,5 @@
public class ClassG extends ClassF {
public void print(String x) {
System.out.println(x);
}
}

View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
ClassF z = new ClassF();
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,5 @@
public class ClassA {
public void print(int x, String y) {
System.out.println(x + " " + y);
}
}

View File

@ -0,0 +1,5 @@
public class ClassB extends ClassA {
public void print(int x) {
System.out.println(x);
}
}

View File

@ -0,0 +1,3 @@
public abstract class ClassC extends ClassA {
public abstract void print(String x, String y);
}

View File

@ -0,0 +1,5 @@
public class ClassD extends ClassC {
public void print(String a, String b) {
System.out.println(a + " " + b);
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
}
}

11
T5Q2-A/T5Q2-A.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

5
T5Q2-A/src/ClassA.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassA {
public void print(int x, String y) {
System.out.println(x + " " + y);
}
}

5
T5Q2-A/src/ClassB.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassB extends ClassA {
public void print(int x) {
System.out.println(x);
}
}

3
T5Q2-A/src/ClassC.java Normal file
View File

@ -0,0 +1,3 @@
public abstract class ClassC extends ClassA {
public abstract void print(String x, String y);
}

5
T5Q2-A/src/ClassD.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassD extends ClassC {
public void print(String a, String b) {
System.out.println(a + " " + b);
}
}

5
T5Q2-A/src/ClassE.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassE extends ClassC {
public void print(String x) {
System.out.println(x);
}
}

5
T5Q2-A/src/ClassF.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassF extends ClassE {
public void print(int x) {
System.out.println(x);
}
}

5
T5Q2-A/src/ClassG.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassG extends ClassF {
public void print(String x) {
System.out.println(x);
}
}

5
T5Q2-A/src/Main.java Normal file
View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
ClassF z = new ClassF();
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,5 @@
public class ClassA {
public void print(int x, String y) {
System.out.println(x + " " + y);
}
}

View File

@ -0,0 +1,5 @@
public class ClassB extends ClassA {
public void print(int x) {
System.out.println(x);
}
}

View File

@ -0,0 +1,3 @@
public abstract class ClassC extends ClassA {
public abstract void print(String x, String y);
}

View File

@ -0,0 +1,5 @@
public class ClassD extends ClassC {
public void print(String a, String b) {
System.out.println(a + " " + b);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,5 @@
public class ClassF extends ClassE {
public void print(int x) {
System.out.println(x);
}
}

View File

@ -0,0 +1,5 @@
public class ClassG extends ClassF {
public void print(String x) {
System.out.println(x);
}
}

View File

@ -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");
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,5 @@
public class ClassA {
public void print(int x, String y) {
System.out.println(x + " " + y);
}
}

View File

@ -0,0 +1,5 @@
public class ClassB extends ClassA {
public void print(int x) {
System.out.println(x);
}
}

View File

@ -0,0 +1,3 @@
public abstract class ClassC extends ClassA {
public abstract void print(String x, String y);
}

View File

@ -0,0 +1,5 @@
public class ClassD extends ClassC {
public void print(String a, String b) {
System.out.println(a + " " + b);
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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");
}
}

11
T5Q2-C/T5Q2-C.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

5
T5Q2-C/src/ClassA.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassA {
public void print(int x, String y) {
System.out.println(x + " " + y);
}
}

5
T5Q2-C/src/ClassB.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassB extends ClassA {
public void print(int x) {
System.out.println(x);
}
}

5
T5Q2-C/src/ClassC.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassC extends ClassA {
public void print(String x, String y) {
System.out.println(x + " " + y);
}
}

5
T5Q2-C/src/ClassD.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassD extends ClassC {
public void print(String a, String b) {
System.out.println(a + " " + b);
}
}

5
T5Q2-C/src/ClassE.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassE extends ClassC {
public void print(String x) {
System.out.println(x);
}
}

5
T5Q2-C/src/ClassF.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassF extends ClassE {
public void print(int x) {
System.out.println(x);
}
}

5
T5Q2-C/src/ClassG.java Normal file
View File

@ -0,0 +1,5 @@
public class ClassG extends ClassF {
public void print(String x) {
System.out.println(x);
}
}

32
T5Q2-C/src/Main.java Normal file
View File

@ -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
}
}

11
T5Q3/T5Q3.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -29,16 +29,6 @@ public class TestPolygon {