From 8cd5b590274fa2a98b92bfcc2b65c03650d6e640 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 23 Sep 2023 20:57:43 +0800 Subject: [PATCH 01/10] Committed on or around 2023/09/23 --- ..._super_to_call_superclass_constructor.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Chapter7/theoretical/Using_super_to_call_superclass_constructor.java diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java new file mode 100644 index 0000000..610d3ae --- /dev/null +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java @@ -0,0 +1,54 @@ +package theoretical; + +class TwoDShaper{ + + private double width; + private double height; + + public TwoDShaper(double w, double h) { + // TODO Auto-generated constructor stub + } + + double getWidth() { + return width; + } + + double getHeight() { + return height; + } + + void setWidth(double w) { + width = w; + } + + void setHeight(double h) { + height = h; + } + + void showDim() { + + System.out.println("Width and height are " + width + " and " + height); + } + +} + + +class Triangular extends TwoDShaper{ + + private String style; + + public Triangular(String s, double w, double h) { + super(w, h); + + style = s; + } +} + +public class Using_super_to_call_superclass_constructor { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 34756d5c07220c8d9671aa7f05c90ce9035baaa9 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 23 Sep 2023 21:05:07 +0800 Subject: [PATCH 02/10] Committed on or around 2023/09/23 --- ..._super_to_call_superclass_constructor.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java index 610d3ae..e989511 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java @@ -42,12 +42,34 @@ public Triangular(String s, double w, double h) { style = s; } + + double area() { + return getWidth() * getHeight() / 2; + } + + void showStyle() { + System.out.println("Triangle is " + style); + } } public class Using_super_to_call_superclass_constructor { public static void main(String[] args) { - // TODO Auto-generated method stub + + Triangular t1 = new Triangular("filled", 4.0, 4.0); + Triangular t2 = new Triangular("outlined", 8.0, 12.0); + + System.out.println("Info for t1: "); + t1.showStyle(); + t1.showDim(); + System.out.println("Area is " + t1.area()); + + System.out.println(); + + System.out.println("Info for t2: "); + t2.showStyle(); + t2.showDim(); + System.out.println("Area is " + t2.area()); } From 7449ce51583b16cc820535329a76354cdb0039c0 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 23 Sep 2023 21:06:40 +0800 Subject: [PATCH 03/10] Committed on or around 2023/09/23 --- .../Using_super_to_call_superclass_constructor.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java index e989511..9e3e923 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor.java @@ -70,6 +70,13 @@ public static void main(String[] args) { t2.showStyle(); t2.showDim(); System.out.println("Area is " + t2.area()); + + System.out.println(); + + System.out.println("Info for t2: "); + t2.showStyle(); + t2.showDim(); + System.out.println("Area is " + t2.area()); } From 673c26a772287f2e33972bae3a9f6678f306a6fb Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 23 Sep 2023 23:50:10 +0800 Subject: [PATCH 04/10] Committed on or around 2023/09/23 --- ...uper_to_call_superclass_constructor_2.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java new file mode 100644 index 0000000..76a4bd4 --- /dev/null +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java @@ -0,0 +1,63 @@ +package theoretical; + +import Cpp.this_keyword; + +class TwoDShaper_2{ + + private double width; + private double height; + private String title; + + public TwoDShaper_2(double w, double h) { + // TODO Auto-generated constructor stub + } + + public TwoDShaper_2() { + // TODO Auto-generated constructor stub + } + + TwoDShaper_2(double width, double height, String title){ + + this.width = width; + this.height = height; + this.title = title; + + } + + + double getWidth() { + return width; + } + + double getHeight() { + return height; + } + + void setWidth(double w) { + width = w; + } + + void setHeight(double h) { + height = h; + } + + void showDim() { + + System.out.println("Width and height are " + width + " and " + height); + } + + String showTitle() { + return title; + } + +} + + +public class Using_super_to_call_superclass_constructor_2 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 26bb2d0ab5d3ce114795f5ffc536b4ab5853fd47 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sat, 23 Sep 2023 23:55:35 +0800 Subject: [PATCH 05/10] Committed on or around 2023/09/23 --- .../Using_super_to_call_superclass_constructor_2.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java index 76a4bd4..169f252 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java @@ -53,6 +53,17 @@ String showTitle() { } +class Triangular_2 extends TwoDShaper_2{ + + private String style; + + public Triangular_2() { + // TODO Auto-generated constructor stub + } + +} + + public class Using_super_to_call_superclass_constructor_2 { public static void main(String[] args) { From 2a0483df3a73d0b2e7c7e9463b76fff3a361dd10 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:00:19 +0800 Subject: [PATCH 06/10] Committed on or around 2023/09/24 --- ...uper_to_call_superclass_constructor_2.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java index 169f252..3c8392e 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java @@ -61,6 +61,28 @@ public Triangular_2() { // TODO Auto-generated constructor stub } + public Triangular_2(String s, double w, double h) { + super(w, h); + + style = s; + } + + Triangular_2(String style, String title, double width, double height){ + + super(width, height, title); + + this.style = style; + + } + + double area() { + return getWidth() * getHeight() / 2; + } + + void showStyle() { + System.out.println("Triangle is " + style); + } + } From 7e4a4bf01452889820bd98b952089274d04585c3 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:01:10 +0800 Subject: [PATCH 07/10] Committed on or around 2023/09/24 --- .../Using_super_to_call_superclass_constructor_2.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java index 3c8392e..5ef913e 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java @@ -1,7 +1,5 @@ package theoretical; -import Cpp.this_keyword; - class TwoDShaper_2{ private double width; From 2781ec98ee1e84f487840672405a20273c3b987d Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:11:51 +0800 Subject: [PATCH 08/10] Committed on or around 2023/09/24 --- ...uper_to_call_superclass_constructor_2.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java index 5ef913e..1efe849 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_2.java @@ -81,6 +81,12 @@ void showStyle() { System.out.println("Triangle is " + style); } + String showTitle() { + + return showTitle(); + + } + } @@ -88,7 +94,29 @@ public class Using_super_to_call_superclass_constructor_2 { public static void main(String[] args) { // TODO Auto-generated method stub - + Triangular_2 t1 = new Triangular_2("filled", 4.0, 4.0); + Triangular_2 t2 = new Triangular_2("outlined", 8.0, 12.0); + Triangular_2 t3 = new Triangular_2("Slovenly", "Classy", 8.0, 9.0); + + System.out.println("Info for t1: "); + t1.showStyle(); + t1.showDim(); + System.out.println("Area is " + t1.area()); + + System.out.println(); + + System.out.println("Info for t2: "); + t2.showStyle(); + t2.showDim(); + System.out.println("Area is " + t2.area()); + + System.out.println(); + + System.out.println("Info for t3: "); + t3.showStyle(); + t3.showDim(); + t3.showTitle(); + System.out.println("Area is " + t3.area()); } } From f503208fdf59f2392eb1c25e86bc269501eafb66 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:16:57 +0800 Subject: [PATCH 09/10] Committed on or around 2023/09/24 --- ...uper_to_call_superclass_constructor_3.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java new file mode 100644 index 0000000..7c06b92 --- /dev/null +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java @@ -0,0 +1,103 @@ +package theoretical; + + +class TwoDShaper_3{ + + private double width; + private double height; + private String title; + + public TwoDShaper_3(double w, double h) { + // TODO Auto-generated constructor stub + } + + public TwoDShaper_3() { + // TODO Auto-generated constructor stub + } + + TwoDShaper_3(double width, double height, String title){ + + this.width = width; + this.height = height; + this.title = title; + + } + + + double getWidth() { + return width; + } + + double getHeight() { + return height; + } + + void setWidth(double w) { + width = w; + } + + void setHeight(double h) { + height = h; + } + + void showDim() { + + System.out.println("Width and height are " + width + " and " + height); + } + + String showTitle() { + return title; + } + +} + + + +class Triangular_3 extends TwoDShaper_3{ + + private String style; + + public Triangular_3() { + // TODO Auto-generated constructor stub + } + + public Triangular_3(String s, double w, double h) { + super(w, h); + + style = s; + } + + Triangular_3(String style, String title, double width, double height){ + + super(width, height, title); + + this.style = style; + + } + + double area() { + return getWidth() * getHeight() / 2; + } + + void showStyle() { + System.out.println("Triangle is " + style); + } + + String showTheTitle() { + + return showTitle(); + + } + +} + + + +public class Using_super_to_call_superclass_constructor_3 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From c910642d24a97695f13d72e17c0ece2f3f1a719f Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:18:33 +0800 Subject: [PATCH 10/10] Committed on or around 2023/09/24 --- ...uper_to_call_superclass_constructor_3.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java index 7c06b92..e974c2a 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_3.java @@ -97,6 +97,30 @@ public class Using_super_to_call_superclass_constructor_3 { public static void main(String[] args) { // TODO Auto-generated method stub + Triangular_3 t1 = new Triangular_3("filled", 4.0, 4.0); + Triangular_3 t2 = new Triangular_3("outlined", 8.0, 12.0); + Triangular_3 t3 = new Triangular_3("Slovenly", "Classy", 8.0, 9.0); + + System.out.println("Info for t1: "); + t1.showStyle(); + t1.showDim(); + System.out.println("Area is " + t1.area()); + + System.out.println(); + + System.out.println("Info for t2: "); + t2.showStyle(); + t2.showDim(); + System.out.println("Area is " + t2.area()); + + System.out.println(); + + System.out.println("Info for t3: "); + t3.showStyle(); + t3.showDim(); + t3.showTitle(); + t3.showTheTitle(); + System.out.println("Area is " + t3.area()); }