Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use an object-oriented language (Java, C#, or C++) to solve the following proble

ID: 3890076 • Letter: U

Question

Use an object-oriented language (Java, C#, or C++) to solve the following problems.

1. Write a pair of classes, Square1 and Rectangle1. Define Square1 as a subclass of Rectangle1. In addition to setters and getters, provide such methods as computeArea and computePerimeter. Specify the preconditions, postconditions and class invariants, if any, as comments

2. Write a pair of classes, Square2 and Rectangle2. Define Rectangle2 as a subclass of Square2. In addition to setters and getters, provide such methods as computeArea and computePerimeter. Specify the preconditions, postconditions and class invariants, if any, as comments

3. Compare (1) and (2), illustrating the pros and cons of (1) and (2), respectively.

Explanation / Answer

1.

2.

3.

For 1:
Pro: Square class will need to implement only the setter and all other functions of the previous class can be used.
Con: Setter function needed to be defined.

For 2:
Pro: Much clearer to understand how calculation on area and perimeter differ.
Con: Functions are nearly same, So give rise to redundancy.