From 2194b0ab9a8e9576f6731dfb7a83cb0758c3430d Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 25 Sep 2023 13:57:20 +0800 Subject: [PATCH 1/6] Committed on or around 2023/09/25 --- .../Using_super_to_call_superclass_constructor_4.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java index 16224c3..d01a16a 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java @@ -103,6 +103,8 @@ public static void main(String[] args) { System.out.println("Info for t0: "); t0.showStyle(); + t0.setHeight(9); + t0.setWidth(3); t0.showDim(); System.out.println("Area is " + t0.area()); From d61a6bc8411f06ac94a45687d151ecb6963d458a Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:07:40 +0800 Subject: [PATCH 2/6] Committed on or around 2023/09/25 --- .../Using_super_to_call_superclass_constructor_4.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java index d01a16a..232cad7 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java @@ -52,7 +52,7 @@ String showTitle() { } -class Triangular_4 extends TwoDShaper_3{ +class Triangular_4 extends TwoDShaper_4{ private String style; From 28f88a7cfd6d70d49d0a9e1286be82f8d5d9d106 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:09:14 +0800 Subject: [PATCH 3/6] Committed on or around 2023/09/25 --- .../Using_super_to_call_superclass_constructor_4.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java index 232cad7..1509910 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java @@ -8,7 +8,8 @@ class TwoDShaper_4{ private String title; public TwoDShaper_4(double w, double h) { - // TODO Auto-generated constructor stub + width = w; + height = h; } public TwoDShaper_4() { From 9ee09dfdf9b1eb951aec44deaad306d45db930d2 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:11:52 +0800 Subject: [PATCH 4/6] Committed on or around 2023/09/25 --- .../Using_super_to_call_superclass_constructor_4.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java index 1509910..e58cc11 100644 --- a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_4.java @@ -107,6 +107,8 @@ public static void main(String[] args) { t0.setHeight(9); t0.setWidth(3); t0.showDim(); + t0.showTitle(); + t0.showTheTitle(); System.out.println("Area is " + t0.area()); System.out.println(); From 46d42ee98b577a0c0923c77a3d9aa1743552f9c4 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:32:10 +0800 Subject: [PATCH 5/6] Committed on or around 2023/09/25 --- ...uper_to_call_superclass_constructor_5.java | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Chapter7/theoretical/Using_super_to_call_superclass_constructor_5.java diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_5.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_5.java new file mode 100644 index 0000000..99fdeae --- /dev/null +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_5.java @@ -0,0 +1,144 @@ +package theoretical; + +class TwoDShaper_5{ + + private double width; + private double height; + String title; + + public TwoDShaper_5(double w, double h) { + width = w; + height = h; + } + + public TwoDShaper_5() { + // TODO Auto-generated constructor stub + } + + TwoDShaper_5(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; + } + + void showTitle_2() { + System.out.println("Triangle is also " + title); + } + +} + + +class Triangular_5 extends TwoDShaper_5{ + + private String style; + + public Triangular_5() { + // TODO Auto-generated constructor stub + } + + public Triangular_5(String s, double w, double h) { + super(w, h); + + style = s; + } + + Triangular_5(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(); + + } + + void showTheTitle_2() { + System.out.println("Triangle is also " + super.title); + } + +} + + +public class Using_super_to_call_superclass_constructor_5 { + + public static void main(String[] args) { + Triangular_5 t0 = new Triangular_5(); + Triangular_5 t1 = new Triangular_5("filled", 4.0, 4.0); + Triangular_5 t2 = new Triangular_5("outlined", 8.0, 12.0); + Triangular_5 t3 = new Triangular_5("Slovenly", "Classy", 8.0, 9.0); + + System.out.println("Info for t0: "); + t0.showStyle(); + t0.setHeight(9); + t0.setWidth(3); + t0.showDim(); + t0.showTitle(); + t0.showTheTitle(); + System.out.println("Area is " + t0.area()); + + System.out.println(); + + 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_2(); + t3.showTheTitle_2(); + System.out.println("Area is " + t3.area()); + + } + +} From 83e66823f8a8ef1f466e939b0b98c51be4538a2d Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:43:39 +0800 Subject: [PATCH 6/6] Committed on or around 2023/09/25 --- ...uper_to_call_superclass_constructor_6.java | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 Chapter7/theoretical/Using_super_to_call_superclass_constructor_6.java diff --git a/Chapter7/theoretical/Using_super_to_call_superclass_constructor_6.java b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_6.java new file mode 100644 index 0000000..a0f932b --- /dev/null +++ b/Chapter7/theoretical/Using_super_to_call_superclass_constructor_6.java @@ -0,0 +1,151 @@ +package theoretical; + + +class TwoDShaper_6{ + + private double width; + private double height; + String title; + + public TwoDShaper_6(double w, double h) { + width = w; + height = h; + } + + public TwoDShaper_6() { + // TODO Auto-generated constructor stub + } + + TwoDShaper_6(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; + } + + void showTitle_2() { + System.out.println("Triangle is also " + title); + } + +} + + +class Triangular_6 extends TwoDShaper_6{ + + private String style; + + public Triangular_6() { + // TODO Auto-generated constructor stub + } + + public Triangular_6(String s, double w, double h) { + super(w, h); + + style = s; + } + + Triangular_6(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(); + + } + + void showTheTitle_2() { + System.out.println("Triangle is also " + super.title); // super is redundant here. + } + + void showTheTitle_3() { + System.out.println("Triangle is also " + title); + } + +} + + +public class Using_super_to_call_superclass_constructor_6 { + + public static void main(String[] args) { + + Triangular_6 t0 = new Triangular_6(); + Triangular_6 t1 = new Triangular_6("filled", 4.0, 4.0); + Triangular_6 t2 = new Triangular_6("outlined", 8.0, 12.0); + Triangular_6 t3 = new Triangular_6("Slovenly", "Classy", 8.0, 9.0); + + System.out.println("Info for t0: "); + t0.showStyle(); + t0.setHeight(9); + t0.setWidth(3); + t0.showDim(); + t0.showTitle(); + t0.showTheTitle(); + System.out.println("Area is " + t0.area()); + + System.out.println(); + + 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_2(); + t3.showTheTitle_2(); + t3.showTheTitle_3(); + System.out.println("Area is " + t3.area()); + + } + +}