From 0adb3fe39ec01a412b848a2f5ed42044c4762959 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 12:32:56 +0800 Subject: [PATCH 01/20] Committed on or around 2023/10/01 --- .../Super_Class_References_and_Subclass_Objects.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter7/theoretical/Super_Class_References_and_Subclass_Objects.java b/Chapter7/theoretical/Super_Class_References_and_Subclass_Objects.java index 0905f5e..9bc860a 100644 --- a/Chapter7/theoretical/Super_Class_References_and_Subclass_Objects.java +++ b/Chapter7/theoretical/Super_Class_References_and_Subclass_Objects.java @@ -86,7 +86,7 @@ public Triangle_2(String s, double w, double h) { } Triangle_2(Triangle_2 ob){ - + super(ob); } From 52fa5931c0ac2f8433f21e0b02522760cb85fc4b Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:04:13 +0800 Subject: [PATCH 02/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Chapter8/Interface/Series_Demo.java diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java new file mode 100644 index 0000000..528be3b --- /dev/null +++ b/Chapter8/Interface/Series_Demo.java @@ -0,0 +1,15 @@ +package Interface; + +// An interface specifies what must be done, but not how to do it. +interface Series2{ + +} + +public class Series_Demo { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 54ff00d98c34225e026a4f22dbb027f068d9d04b Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:34:16 +0800 Subject: [PATCH 03/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index 528be3b..69e82a7 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -3,6 +3,9 @@ // An interface specifies what must be done, but not how to do it. interface Series2{ + int getNext(); + void reset(); + void setStart(int x); } public class Series_Demo { From 0a4b2f79b079b8212cffb61e247c0e5c20d260bd Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:53:52 +0800 Subject: [PATCH 04/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index 69e82a7..8664625 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -8,10 +8,26 @@ interface Series2{ void setStart(int x); } + +// Implement Series. +class ByTwos implements Series2{ + int start; + int value; + + public ByTwos() { + start = 0; + value = 0; + } + + int getNext() { + + } +} + public class Series_Demo { public static void main(String[] args) { - // TODO Auto-generated method stub + } From c6c5d419f2ea1fa8884e506862c50d3afbe05850 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:59:10 +0800 Subject: [PATCH 05/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index 8664625..efd189c 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -19,8 +19,9 @@ public ByTwos() { value = 0; } - int getNext() { - + public int getNext() { + value += 2; + return value; } } From edac15bb2a03547b7f3984ec64a714a64e8fbba2 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:02:16 +0800 Subject: [PATCH 06/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index efd189c..d5b3774 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -19,10 +19,16 @@ public ByTwos() { value = 0; } + // Whenever you implement a method defined by an interface, it must be implemented as public; + // because all members of an interface are implicitly public. public int getNext() { value += 2; return value; } + + public void reset() { + value = start; + } } public class Series_Demo { From 7578b79bb9b0b01a56c02dcb35ea90d36c869e7e Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:05:44 +0800 Subject: [PATCH 07/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index d5b3774..f1e3096 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -10,11 +10,11 @@ interface Series2{ // Implement Series. -class ByTwos implements Series2{ +class ByTwos2 implements Series2{ int start; int value; - public ByTwos() { + public ByTwos2() { start = 0; value = 0; } @@ -29,6 +29,12 @@ public int getNext() { public void reset() { value = start; } + + @Override + public void setStart(int x) { + // TODO Auto-generated method stub + + } } public class Series_Demo { From 6cf437d86b708cfca2fef5e17f7f21a23c97f6be Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:24:31 +0800 Subject: [PATCH 08/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index f1e3096..d31797b 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -32,7 +32,9 @@ public void reset() { @Override public void setStart(int x) { - // TODO Auto-generated method stub + + start = x; + value = x; } } From 515a00cdd187e1e04f1726c7e5a81ee4be3f9ef3 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:01:59 +0800 Subject: [PATCH 09/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 1 + Chapter8/Interface/Series_Demo2.java | 58 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Chapter8/Interface/Series_Demo2.java diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index d31797b..646bf15 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -43,6 +43,7 @@ public class Series_Demo { public static void main(String[] args) { + ByTwos2 oByTwos2 = new ByTwos2(); } diff --git a/Chapter8/Interface/Series_Demo2.java b/Chapter8/Interface/Series_Demo2.java new file mode 100644 index 0000000..ff4ddd3 --- /dev/null +++ b/Chapter8/Interface/Series_Demo2.java @@ -0,0 +1,58 @@ +package Interface; + +//An interface specifies what must be done, but not how to do it. +interface Series3{ + + int getNext(); + void reset(); + void setStart(int x); +} + + +//Implement Series. +class ByTwos3 implements Series3{ + int start; + int value; + int previous; + + public ByTwos3() { + start = 0; + value = 0; + } + + ByTwos3(int previous) { + + this.previous = previous; + + start = 0; + value = 0; + } + + // Whenever you implement a method defined by an interface, it must be implemented as public; + // because all members of an interface are implicitly public. + public int getNext() { + value += 2; + return value; + } + + public void reset() { + value = start; + } + + @Override + public void setStart(int x) { + + start = x; + value = x; + + } +} + +public class Series_Demo2 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From c58c31c3b183f947fd5fd98926986ab35290d5cb Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:09:53 +0800 Subject: [PATCH 10/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo2.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Chapter8/Interface/Series_Demo2.java b/Chapter8/Interface/Series_Demo2.java index ff4ddd3..5225b89 100644 --- a/Chapter8/Interface/Series_Demo2.java +++ b/Chapter8/Interface/Series_Demo2.java @@ -46,6 +46,10 @@ public void setStart(int x) { value = x; } + + int getPrevious() { + return previous; + } } public class Series_Demo2 { From 1ca38ce735700ad698dfefdcb427ffcfa6c0d4d4 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:29:01 +0800 Subject: [PATCH 11/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo2.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Chapter8/Interface/Series_Demo2.java b/Chapter8/Interface/Series_Demo2.java index 5225b89..df2b91f 100644 --- a/Chapter8/Interface/Series_Demo2.java +++ b/Chapter8/Interface/Series_Demo2.java @@ -56,6 +56,8 @@ public class Series_Demo2 { public static void main(String[] args) { // TODO Auto-generated method stub + + ByTwos3 obByTwos3 = new ByTwos3(9); } From e8d7a68b9b4110b7278d52e0497028b7e45deb53 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:38:07 +0800 Subject: [PATCH 12/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Chapter8/Interface/Series_Demo.java b/Chapter8/Interface/Series_Demo.java index 646bf15..8e259e4 100644 --- a/Chapter8/Interface/Series_Demo.java +++ b/Chapter8/Interface/Series_Demo.java @@ -44,6 +44,27 @@ public class Series_Demo { public static void main(String[] args) { ByTwos2 oByTwos2 = new ByTwos2(); + + for (int i = 0; i < 5; i++) { + + System.out.println("Next value is " + oByTwos2.getNext()); + } + + System.out.println("\nResetting"); + + oByTwos2.reset(); + + for (int i = 0; i < 5; i++) { + System.out.println("Next value is " + oByTwos2.getNext()); + } + + System.out.println("\nStarting at 100"); + + oByTwos2.setStart(100); + + for (int i = 0; i < 5; i++) { + System.out.println("Next value is " + oByTwos2.getNext()); + } } From ecfc002dc054ba9c9ebd7dbe171b098b11f2b516 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:48:17 +0800 Subject: [PATCH 13/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo2.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Chapter8/Interface/Series_Demo2.java b/Chapter8/Interface/Series_Demo2.java index df2b91f..1c31a27 100644 --- a/Chapter8/Interface/Series_Demo2.java +++ b/Chapter8/Interface/Series_Demo2.java @@ -58,6 +58,27 @@ public static void main(String[] args) { // TODO Auto-generated method stub ByTwos3 obByTwos3 = new ByTwos3(9); + + + for (int i = 0; i < 5; i++) { + System.out.println("Next value is " + obByTwos3.getNext()); + } + + System.out.println("\nResetting"); + + obByTwos3.reset(); + + for (int i = 0; i < 5; i++) { + System.out.println("Next value is " + obByTwos3.getNext()); + } + + System.out.println("\n Starting at 100"); + obByTwos3.setStart(100); + + for (int i = 0; i < 5; i++) { + + System.out.println("Next value is " + obByTwos3.getNext()); + } } From d0727c948f3850040faa277e8317f1796b7e8c4a Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:49:54 +0800 Subject: [PATCH 14/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter8/Interface/Series_Demo2.java b/Chapter8/Interface/Series_Demo2.java index 1c31a27..6fac31c 100644 --- a/Chapter8/Interface/Series_Demo2.java +++ b/Chapter8/Interface/Series_Demo2.java @@ -72,7 +72,7 @@ public static void main(String[] args) { System.out.println("Next value is " + obByTwos3.getNext()); } - System.out.println("\n Starting at 100"); + System.out.println("\nStarting at 100"); obByTwos3.setStart(100); for (int i = 0; i < 5; i++) { From e19b2e648f2df64a39c00da4dfdd414c4ebd3584 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:13:59 +0800 Subject: [PATCH 15/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Series_Demo2.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Chapter8/Interface/Series_Demo2.java b/Chapter8/Interface/Series_Demo2.java index 6fac31c..cc89a73 100644 --- a/Chapter8/Interface/Series_Demo2.java +++ b/Chapter8/Interface/Series_Demo2.java @@ -73,6 +73,7 @@ public static void main(String[] args) { } System.out.println("\nStarting at 100"); + obByTwos3.setStart(100); for (int i = 0; i < 5; i++) { From 3eb8547e330055a705c37fbb4945ec252d16f776 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:35:26 +0800 Subject: [PATCH 16/20] Committed on or around 2023/10/01 --- .../Interface/Implementing_Interfaces.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Chapter8/Interface/Implementing_Interfaces.java diff --git a/Chapter8/Interface/Implementing_Interfaces.java b/Chapter8/Interface/Implementing_Interfaces.java new file mode 100644 index 0000000..54d03da --- /dev/null +++ b/Chapter8/Interface/Implementing_Interfaces.java @@ -0,0 +1,96 @@ +package Interface; + +//An interface specifies what must be done, but not how to get it done. +interface Series4{ + + int getNext(); + void reset(); + void setStart(int x); +} + + +//Implement Series. +class ByTwos2_ implements Series4{ + + // It's both permissible and common for classes that implement interfaces to define additional members + // of their own. (It absolutely is. Without it, how to implement methods in an interface?) + int start; + int value; + + public ByTwos2_() { + start = 0; + value = 0; + } + + // Whenever you implement a method defined by an interface, it must be implemented as public; + // because all members of an interface are implicitly public. + public int getNext() { + value += 2; + return value; + } + + public void reset() { + value = start; + } + + @Override + public void setStart(int x) { + + start = x; + value = x; + + } +} + + +class ByTwos4 implements Series4{ + int start; + int value; + int previous; + + public ByTwos4() { + start = 0; + value = 0; + } + + ByTwos4(int previous) { + + this.previous = previous; + + start = 0; + value = 0; + } + + // Whenever you implement a method defined by an interface, it must be implemented as public; + // because all members of an interface are implicitly public. + public int getNext() { + value += 2; + return value; + } + + public void reset() { + value = start; + } + + @Override + public void setStart(int x) { + + start = x; + value = x; + + } + + int getPrevious() { + return previous; + } +} + + +public class Implementing_Interfaces { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 2eeb18cb0eeb924ad2a22b3de68483ece0c67abd Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:46:00 +0800 Subject: [PATCH 17/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Implementing_Interfaces.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Chapter8/Interface/Implementing_Interfaces.java b/Chapter8/Interface/Implementing_Interfaces.java index 54d03da..23f6a67 100644 --- a/Chapter8/Interface/Implementing_Interfaces.java +++ b/Chapter8/Interface/Implementing_Interfaces.java @@ -80,6 +80,8 @@ public void setStart(int x) { } + // Even though the interface does not define this method, it's both permissible and common for classes + // that implement interfaces to define additional members of their own. int getPrevious() { return previous; } From b1c1432492613cd605472af57b57ce7df08226b9 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:59:30 +0800 Subject: [PATCH 18/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Implementing_Interfaces.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Chapter8/Interface/Implementing_Interfaces.java b/Chapter8/Interface/Implementing_Interfaces.java index 23f6a67..043576b 100644 --- a/Chapter8/Interface/Implementing_Interfaces.java +++ b/Chapter8/Interface/Implementing_Interfaces.java @@ -88,6 +88,18 @@ int getPrevious() { } +class ByThrees implements Series4{ // implement Series in a different way. + int start; + int value; + + public ByThrees() { + // TODO Auto-generated constructor stub + start = 0; + value = 0; + } +} + + public class Implementing_Interfaces { public static void main(String[] args) { From 7b4d2e1fd68edcbef0ba256ae827ba414ad45eb5 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 19:03:37 +0800 Subject: [PATCH 19/20] Committed on or around 2023/10/01 --- Chapter8/Interface/Implementing_Interfaces.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Chapter8/Interface/Implementing_Interfaces.java b/Chapter8/Interface/Implementing_Interfaces.java index 043576b..9fb1e33 100644 --- a/Chapter8/Interface/Implementing_Interfaces.java +++ b/Chapter8/Interface/Implementing_Interfaces.java @@ -92,11 +92,25 @@ class ByThrees implements Series4{ // implement Series in a different way. int start; int value; - public ByThrees() { + ByThrees() { // TODO Auto-generated constructor stub start = 0; value = 0; } + + public int getNext() { + value += 3; + return value; + } + + public void reset() { + value = start; + } + + public void setStart(int x) { + start = x; + value = x; + } } From a82c06858ead9fef73703a3d831ceaeb3993782f Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 1 Oct 2023 19:28:08 +0800 Subject: [PATCH 20/20] Committed on or around 2023/10/01 --- .../Interface/Implementing_Interfaces.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Chapter8/Interface/Implementing_Interfaces.java b/Chapter8/Interface/Implementing_Interfaces.java index 9fb1e33..905d08e 100644 --- a/Chapter8/Interface/Implementing_Interfaces.java +++ b/Chapter8/Interface/Implementing_Interfaces.java @@ -1,5 +1,7 @@ package Interface; +import Cpp.this_keyword; + //An interface specifies what must be done, but not how to get it done. interface Series4{ @@ -88,11 +90,11 @@ int getPrevious() { } -class ByThrees implements Series4{ // implement Series in a different way. +class ByThrees2 implements Series4{ // implement Series in a different way. int start; int value; - ByThrees() { + ByThrees2() { // TODO Auto-generated constructor stub start = 0; value = 0; @@ -114,6 +116,19 @@ public void setStart(int x) { } +// If a class includes an interface but does not fully implement the methods defined by that interface, then +// that class must be declared as abstract. +abstract class implicate implements Series4{ + + int start; + + public void setStart(int start) { + this.start = start; + } + +} + + public class Implementing_Interfaces { public static void main(String[] args) {