Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER TO ALL MY QUESTIONS. 1. What does it mean to parameterize a data type? 2. In our ArrayList class, we still used an

PLEASE ANSWER TO ALL MY QUESTIONS. 1. What does it mean to "parameterize a data type"? 2. In our ArrayList class, we still used an array as the underlying data structure. What data type did we declare it to be and why was that necessary? 3. In SuperAndSub, what do the default constructors for each of the classes do?

4. In SuperAndSub, when the SubClass object is created which class constructor completes execution first? Why do you think that is the case? 5. What was the hardest part of this lab for you and why was it hard.

Arraylisttester;

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

SuperAndSub

image text in transcribed

superandsub;

image text in transcribed

image text in transcribed

public class ConcreteSubSuper extends AbstractSuper { private int property1; private int property2; public ConcreteSubSuper(){ this(0,0,0,0); }

/** * * @param superProp1 * @param superProp2 * @param property1 * @param property2 */ public ConcreteSubSuper(int superProp1, int superProp2, int property1, int property2){ super(superProp1, superProp2); this.property1 = property1; this.property2 = property2; System.out.println("Finished Executing: constructor in " + "ConcreteSubSuper"); }

/** * There is an m in the super class */ @Override public void m(){ System.out.println("Executing ConcreteSubSuper's m()"); property1 *= 2; System.out.println("Calling: super.m();"); super.m(); } /** * this one is an overloaded method: same name, different signature. * @param p */ public void m(int p){ System.out.println("Executing ConcreteSubSuper's m(int)"); property2 = p + property2; } @Override public int n() { System.out.println("Executing: ConcreteSubSuper's n()"); System.out.println("Calling: super.p();"); super.p(); return super.property2; } public String toString(){ StringBuilder str = new StringBuilder(); String eol = System.lineSeparator(); str.append(super.toString()).append(eol); str.append(String.format("In the ConcretSubSuper class " + "property1 is %d and property2 is %d", property1, property2)); return str.toString(); }

}

*/ private boolean isValidIndex(int index) { return (index >= 0 && index index; i--) { array[i] = array[i - 1]; } array[index] = element; size++; return true; } 96 97 98 99 100 101 102 103 public int get(int index) { if (isValidIndex(index)) { return array[index]; } else { return -1; } } /** * Finds the element specified and returns the index if found or -1 if not * found. performs a standard linear search if the array contains the * element. * 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 * @param element the element to search for * @return the index of the element or -1 if the element is in in the list */ public int indexOf(int element) { int index = 0; if (contains (element)) { while (index 0 && i % 20 == 0) { str.append(System.line Separator()); } } str.append(array[size - 1]); str.append("]"); } return str.toString(); } } 14 public class SuperAndSub { 15 public void run() { 16 System.out.println("Executing: " 17 + "Concrete SubSuper css = new Concrete SubSuper (1,2,3,4);"); 18 Concrete SubSuper css = new Concrete SubSuper (1,2,3,4); 19 System.out.println("One ConcreteSubSuper object created "); 20 System.out.println("contents of css: " + css); 21 System.out.println(" ======= === "); 22 23 System.out.println("Executing: " 24 + "Subclass sc = new Subclass (5,6,7,8,9,10);"); 25 Subclass sc = new Subclass (5,6,7,8,9,10); 26 System.out.println("One Subclass object created "); 27 System.out.println("contents of sc: " + Sc); 28 System.out.println(" ===== "); 29 30 System.out.println("Calling: css.m(12);"); 31 CSS.m(12); 32 System.out.println("contents of css: " + css); 33 System.out.println(" ======== === "); 34 System.out.println("Calling: css.p();"); 35 css.p(); 36 System.out.println("contents of css: " + css); 37 System.out.println(" ====== "); 38 System.out.println("Calling: sc.m(15);"); 39 sc.m(15); 40 System.out.println("contents of sc: " + sc); 41 System.out.println(" ======== ===== "); 42 System.out.println("Calling: sc.n();"); 43 sc.n(); 44 System.out.println("contents of sc: " + sc); 45 46 47 } 48 /** 49 * @param args the command line arguments 50 */ 51 public static void main(String[] args) { 52 // uses a default constructor provided by Java 53 SuperAndSub ss = new SuperAndSub(); 54 ss.run(); 55 56 public class Subclass extends Concrete SubSuper{ private int property1; private int property2; */ public Subclass() { this(0,0,0,0,0,0); } WI * @param super SuperPropi * @param super Super Prop2 * @param super Propi * @param super Prop2 * @param propertyl * @param property2 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 Ir public Subclass(int super Super Propi, int super SuperProp2, int superPropi, int super Prop2, int propertyi, int property2) { super (super SuperPropi, super SuperProp2, superPropi, superProp2); this.property1 = property1; this.property2 = property2; System.out.println("Finished Executing: constructor in Subclass."); } W /** * overrides the one in AbstractSuper */ @Override public void p() { System.out.println("Executing SubClass's PO"); property2 = property1 * property2; BE /** * overrides the one in ConcreteSubSuper */ 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 /** * overrides the one in AbstractSuper */ @Override public void p(){ System.out.println("Executing Subclass's p()"); property2 = property1 * property2; } /** * overrides the one in ConcreteSubSuper */ @Override public void m() { System.out.println("Executing Subclass's m()"); System.out.println("Calling: super.m();"); super.m(); } public String toString() { StringBuilder str = new StringBuilder(); String eol = System.line Separator(); str.append(super.toString()).append(eol); str.append(String.format("In the Subclass class " + "propertyl is %d and property2 is %d", propertyl, property2)); return str.toString(); } 65 66 67 68 69 70 71 72 } */ private boolean isValidIndex(int index) { return (index >= 0 && index index; i--) { array[i] = array[i - 1]; } array[index] = element; size++; return true; } 96 97 98 99 100 101 102 103 public int get(int index) { if (isValidIndex(index)) { return array[index]; } else { return -1; } } /** * Finds the element specified and returns the index if found or -1 if not * found. performs a standard linear search if the array contains the * element. * 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 * @param element the element to search for * @return the index of the element or -1 if the element is in in the list */ public int indexOf(int element) { int index = 0; if (contains (element)) { while (index 0 && i % 20 == 0) { str.append(System.line Separator()); } } str.append(array[size - 1]); str.append("]"); } return str.toString(); } } 14 public class SuperAndSub { 15 public void run() { 16 System.out.println("Executing: " 17 + "Concrete SubSuper css = new Concrete SubSuper (1,2,3,4);"); 18 Concrete SubSuper css = new Concrete SubSuper (1,2,3,4); 19 System.out.println("One ConcreteSubSuper object created "); 20 System.out.println("contents of css: " + css); 21 System.out.println(" ======= === "); 22 23 System.out.println("Executing: " 24 + "Subclass sc = new Subclass (5,6,7,8,9,10);"); 25 Subclass sc = new Subclass (5,6,7,8,9,10); 26 System.out.println("One Subclass object created "); 27 System.out.println("contents of sc: " + Sc); 28 System.out.println(" ===== "); 29 30 System.out.println("Calling: css.m(12);"); 31 CSS.m(12); 32 System.out.println("contents of css: " + css); 33 System.out.println(" ======== === "); 34 System.out.println("Calling: css.p();"); 35 css.p(); 36 System.out.println("contents of css: " + css); 37 System.out.println(" ====== "); 38 System.out.println("Calling: sc.m(15);"); 39 sc.m(15); 40 System.out.println("contents of sc: " + sc); 41 System.out.println(" ======== ===== "); 42 System.out.println("Calling: sc.n();"); 43 sc.n(); 44 System.out.println("contents of sc: " + sc); 45 46 47 } 48 /** 49 * @param args the command line arguments 50 */ 51 public static void main(String[] args) { 52 // uses a default constructor provided by Java 53 SuperAndSub ss = new SuperAndSub(); 54 ss.run(); 55 56 public class Subclass extends Concrete SubSuper{ private int property1; private int property2; */ public Subclass() { this(0,0,0,0,0,0); } WI * @param super SuperPropi * @param super Super Prop2 * @param super Propi * @param super Prop2 * @param propertyl * @param property2 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 Ir public Subclass(int super Super Propi, int super SuperProp2, int superPropi, int super Prop2, int propertyi, int property2) { super (super SuperPropi, super SuperProp2, superPropi, superProp2); this.property1 = property1; this.property2 = property2; System.out.println("Finished Executing: constructor in Subclass."); } W /** * overrides the one in AbstractSuper */ @Override public void p() { System.out.println("Executing SubClass's PO"); property2 = property1 * property2; BE /** * overrides the one in ConcreteSubSuper */ 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 /** * overrides the one in AbstractSuper */ @Override public void p(){ System.out.println("Executing Subclass's p()"); property2 = property1 * property2; } /** * overrides the one in ConcreteSubSuper */ @Override public void m() { System.out.println("Executing Subclass's m()"); System.out.println("Calling: super.m();"); super.m(); } public String toString() { StringBuilder str = new StringBuilder(); String eol = System.line Separator(); str.append(super.toString()).append(eol); str.append(String.format("In the Subclass class " + "propertyl is %d and property2 is %d", propertyl, property2)); return str.toString(); } 65 66 67 68 69 70 71 72 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions

Question

3. Comment on how diversity and equality should be managed.

Answered: 1 week ago

Question

describe the legislation that addresses workplace equality

Answered: 1 week ago