Due: 7 May @ 11:59 pm* [CSE 007] Lab 11: Classes, Inheritance & Polymorphism Date Assigned:...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Due: 7 May @ 11:59 pm* [CSE 007] Lab 11: Classes, Inheritance & Polymorphism Date Assigned: 29 April 2022 Objective: The purpose of this activity is to explore a Shape object that serves as the parent for at least 3 other shapes (i.e. classes that extend Shape or inherit visible members) in order to intentionally incorporate inheritance and polymorphism into a program. Submission: Shape.java, Rectangle.java, Triangle.java, Circle.java, ShapeTest.java *no additional extensions will be granted; This is after the last day of classes. The third pillar of object-oriented programming is polymorphism. This is the idea that given derived classes (created through the use of inheritance), we can use a reference variable of a superType to hold a reference to a subType object. This program will utilize an abstract super class. Abstract classes are like the typical concrete object classes that we have been utilizing, with a few main differences: 1. The class declaration includes the abstract modifier; Ex: a. public abstract class Shape {} 2. You cannot create an instance of an abstract class. As such, we change the constructors of this class to be protected so that only derived classes can access them through constructor chaining. a. protected Shape (String color, String name) {} 3. Although you cannot create an instance of an abstract class, you can use an abstract class as a data type to hold references of derived classes (using Polymorphism). a. Shape [] shapes = new Shape [2]; b. shapes [0] = new Circle(); c. shapes [1] = new Rectangle(); 4. Methods that will be overridden in derived classes should be declared as abstract in the parent class. a. public abstract double computeArea (); b. Note that there is no method body or curly braces, just a semicolon to end the declaration. 5. Any class with (access to) abstract methods is abstract, but a class does not have to have any abstract methods to be defined as abstract. a. This means that if a child class extends an abstract parent class, they must override those abstract methods that were previously declared in the parent class. For this assignment, you will create at least 5 classes: Shape.java, Circle.java, Triangle.java, Rectangle, and ShapeTest.java. Shape will serve as the SuperClass, from which Circle, Triangle and Rectangle will be derived. ShapeTest.java will hold the main method used to create instances of these objects and test the code that you create. public abstract class Shape {}: This class represents an abstract superclass, and includes only a few members (described below). Private Data Field(s): o private String color; o private String name; O private static int numShapes=0; //to hold the number of shape objects created Methods o Protected Constructor(s): overload the constructor method at least 2 times to initialize any combination of data fields. Note: protected means that all child classes (here, circle, rectangle and triangle) have access to the constructors but that they are not visible outside of those classes. o Getter/Setter methods: create methods to access and modify private data fields O Create computeArea () and compute Perimeter () declared as abstract methods. These methods will be overridden in the subclasses that you will define o Overridden methods: override toString (from the object class) to return the shape name and color. public class Circle{}: This is a direct child/subclass to Shape, and is described here. Private Data Field(s): o private double radius; o private static int numCircles=0; //to hold the number of circle objects created Methods o Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Circle and within the super class. O Getter/Setter methods: create methods to access and modify radius O Override computeArea () to calculate the area of the circle and return the value as a double As a reminder, the formula to calculate the area of a circle is: A=T*(radius) o Override compute Perimeter () to calculate the perimeter of the circle and return the value as a double As a reminder, the formula to calculate the perimeter of a circle is: P=2*T*radius public class Triangle{}: This is a direct child/subclass to Shape, and is described here. Override toString (from the Shape ass) to return super.toString() concatenated with the radius and area of the shape. Private Data Field(s): o private double base; o private double height; o private static int numTris=0; //to hold the number of triangle objects created O Methods O Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Triangle and within the super class. Getter/Setter methods: create methods to access and modify the private data fields O Override computeArea () to calculate the area of the triangle and return the value as a double As a reminder, the formula to calculate the area of a triangle is: A=12*base *height O Override compute Perimeter () to calculate the perimeter of the triangle and return the value as a double As a reminder, the formula to calculate the perimeter of a triangle is: P=x+y+base, where x and y are the length of the other two sides for the triangle Be sure to validate these values as positive doubles You can ask the user for input here for the length of the other two sides (since you already have the base), or you can incorporate those values as private data fields to be initialized within the constructor(s). O Override toString (from the Shape class) to return super.toString() concatenated with the base, height and area of the shape. public class Rectangle{}: This is a direct child/subclass to Shape, and is described here. Private Data Field(s): O double length; O double width; O static int numRects=0; //to hold the number of rectangle objects created Methods O Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Rectangle and within the super class. o Getter/Setter methods: create methods to access and modify the private data fields O Override computeArea () to calculate the area of the triangle and return the value as a double As a reminder, the formula to calculate the area of a rectangle is: A-length*width Override compute Perimeter () to calculate the perimeter of the triangle and return the value as a double As a reminder, the formula to calculate the perimeter of a triangle is: P=(2*length) + (2*width) O Override toString (from the Shape class) to return super.toString() concatenated with the base, height and area of the shape. O public class ShapeTest{}: This class will include a main method to test the Shape, Circle and Triangle classes that you previously created. The main method you create should be simple enough to test your code, but also highlight the power of polymorphism, afforded through the use of object-oriented programming and inheritance. Your program should include a modularized main class (using methods) to do the following: An array of shapes that includes references to all types of concrete shape objects Allows the user to manually create a variety in the array O Be sure to validate any input, allowing the user to indicate what shape they are creating o Only one scanner should be used per program Randomly create shapes in the array (and pass in random values to constructors) Display each object, including the perimeter and area O You should use the toString() methods that you have overridden for this O Note that you do not have to explicitly invoke the toString method within a print statement. Display the total perimeter of all objects Display the total area of all objects Display the average perimeter and area for all Shapes. Suggestion: throughout this class (and the others that you create), add comments explaining the various concepts of OOP that you are utilizing. Due: 7 May @ 11:59 pm* [CSE 007] Lab 11: Classes, Inheritance & Polymorphism Date Assigned: 29 April 2022 Objective: The purpose of this activity is to explore a Shape object that serves as the parent for at least 3 other shapes (i.e. classes that extend Shape or inherit visible members) in order to intentionally incorporate inheritance and polymorphism into a program. Submission: Shape.java, Rectangle.java, Triangle.java, Circle.java, ShapeTest.java *no additional extensions will be granted; This is after the last day of classes. The third pillar of object-oriented programming is polymorphism. This is the idea that given derived classes (created through the use of inheritance), we can use a reference variable of a superType to hold a reference to a subType object. This program will utilize an abstract super class. Abstract classes are like the typical concrete object classes that we have been utilizing, with a few main differences: 1. The class declaration includes the abstract modifier; Ex: a. public abstract class Shape {} 2. You cannot create an instance of an abstract class. As such, we change the constructors of this class to be protected so that only derived classes can access them through constructor chaining. a. protected Shape (String color, String name) {} 3. Although you cannot create an instance of an abstract class, you can use an abstract class as a data type to hold references of derived classes (using Polymorphism). a. Shape [] shapes = new Shape [2]; b. shapes [0] = new Circle(); c. shapes [1] = new Rectangle(); 4. Methods that will be overridden in derived classes should be declared as abstract in the parent class. a. public abstract double computeArea (); b. Note that there is no method body or curly braces, just a semicolon to end the declaration. 5. Any class with (access to) abstract methods is abstract, but a class does not have to have any abstract methods to be defined as abstract. a. This means that if a child class extends an abstract parent class, they must override those abstract methods that were previously declared in the parent class. Due: 7 May @ 11:59 pm* [CSE 007] Lab 11: Classes, Inheritance & Polymorphism Date Assigned: 29 April 2022 Objective: The purpose of this activity is to explore a Shape object that serves as the parent for at least 3 other shapes (i.e. classes that extend Shape or inherit visible members) in order to intentionally incorporate inheritance and polymorphism into a program. Submission: Shape.java, Rectangle.java, Triangle.java, Circle.java, ShapeTest.java *no additional extensions will be granted; This is after the last day of classes. The third pillar of object-oriented programming is polymorphism. This is the idea that given derived classes (created through the use of inheritance), we can use a reference variable of a superType to hold a reference to a subType object. This program will utilize an abstract super class. Abstract classes are like the typical concrete object classes that we have been utilizing, with a few main differences: 1. The class declaration includes the abstract modifier; Ex: a. public abstract class Shape {} 2. You cannot create an instance of an abstract class. As such, we change the constructors of this class to be protected so that only derived classes can access them through constructor chaining. a. protected Shape (String color, String name) {} 3. Although you cannot create an instance of an abstract class, you can use an abstract class as a data type to hold references of derived classes (using Polymorphism). a. Shape [] shapes = new Shape [2]; b. shapes [0] = new Circle(); c. shapes [1] = new Rectangle(); 4. Methods that will be overridden in derived classes should be declared as abstract in the parent class. a. public abstract double computeArea (); b. Note that there is no method body or curly braces, just a semicolon to end the declaration. 5. Any class with (access to) abstract methods is abstract, but a class does not have to have any abstract methods to be defined as abstract. a. This means that if a child class extends an abstract parent class, they must override those abstract methods that were previously declared in the parent class. For this assignment, you will create at least 5 classes: Shape.java, Circle.java, Triangle.java, Rectangle, and ShapeTest.java. Shape will serve as the SuperClass, from which Circle, Triangle and Rectangle will be derived. ShapeTest.java will hold the main method used to create instances of these objects and test the code that you create. public abstract class Shape {}: This class represents an abstract superclass, and includes only a few members (described below). Private Data Field(s): o private String color; o private String name; O private static int numShapes=0; //to hold the number of shape objects created Methods o Protected Constructor(s): overload the constructor method at least 2 times to initialize any combination of data fields. Note: protected means that all child classes (here, circle, rectangle and triangle) have access to the constructors but that they are not visible outside of those classes. o Getter/Setter methods: create methods to access and modify private data fields O Create computeArea () and compute Perimeter () declared as abstract methods. These methods will be overridden in the subclasses that you will define o Overridden methods: override toString (from the object class) to return the shape name and color. public class Circle{}: This is a direct child/subclass to Shape, and is described here. Private Data Field(s): o private double radius; o private static int numCircles=0; //to hold the number of circle objects created Methods o Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Circle and within the super class. O Getter/Setter methods: create methods to access and modify radius O Override computeArea () to calculate the area of the circle and return the value as a double As a reminder, the formula to calculate the area of a circle is: A=T*(radius) o Override compute Perimeter () to calculate the perimeter of the circle and return the value as a double As a reminder, the formula to calculate the perimeter of a circle is: P=2*T*radius public class Triangle{}: This is a direct child/subclass to Shape, and is described here. Override toString (from the Shape ass) to return super.toString() concatenated with the radius and area of the shape. Private Data Field(s): o private double base; o private double height; o private static int numTris=0; //to hold the number of triangle objects created O Methods O Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Triangle and within the super class. Getter/Setter methods: create methods to access and modify the private data fields O Override computeArea () to calculate the area of the triangle and return the value as a double As a reminder, the formula to calculate the area of a triangle is: A=12*base *height O Override compute Perimeter () to calculate the perimeter of the triangle and return the value as a double As a reminder, the formula to calculate the perimeter of a triangle is: P=x+y+base, where x and y are the length of the other two sides for the triangle Be sure to validate these values as positive doubles You can ask the user for input here for the length of the other two sides (since you already have the base), or you can incorporate those values as private data fields to be initialized within the constructor(s). For this assignment, you will create at least 5 classes: Shape.java, Circle.java, Triangle.java, Rectangle, and ShapeTest.java. Shape will serve as the SuperClass, from which Circle, Triangle and Rectangle will be derived. ShapeTest.java will hold the main method used to create instances of these objects and test the code that you create. public abstract class Shape {}: This class represents an abstract superclass, and includes only a few members (described below). Private Data Field(s): o private String color; o private String name; O private static int numShapes=0; //to hold the number of shape objects created Methods o Protected Constructor(s): overload the constructor method at least 2 times to initialize any combination of data fields. Note: protected means that all child classes (here, circle, rectangle and triangle) have access to the constructors but that they are not visible outside of those classes. o Getter/Setter methods: create methods to access and modify private data fields O Create computeArea () and compute Perimeter () declared as abstract methods. These methods will be overridden in the subclasses that you will define o Overridden methods: override toString (from the object class) to return the shape name and color. public class Circle{}: This is a direct child/subclass to Shape, and is described here. Private Data Field(s): o private double radius; o private static int numCircles=0; //to hold the number of circle objects created Methods o Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Circle and within the super class. O Getter/Setter methods: create methods to access and modify radius O Override computeArea () to calculate the area of the circle and return the value as a double As a reminder, the formula to calculate the area of a circle is: A=T*(radius) o Override compute Perimeter () to calculate the perimeter of the circle and return the value as a double As a reminder, the formula to calculate the perimeter of a circle is: P=2*T*radius public class Triangle{}: This is a direct child/subclass to Shape, and is described here. Override toString (from the Shape ass) to return super.toString() concatenated with the radius and area of the shape. Private Data Field(s): o private double base; o private double height; o private static int numTris=0; //to hold the number of triangle objects created O Methods O Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Triangle and within the super class. Getter/Setter methods: create methods to access and modify the private data fields O Override computeArea () to calculate the area of the triangle and return the value as a double As a reminder, the formula to calculate the area of a triangle is: A=12*base *height O Override compute Perimeter () to calculate the perimeter of the triangle and return the value as a double As a reminder, the formula to calculate the perimeter of a triangle is: P=x+y+base, where x and y are the length of the other two sides for the triangle Be sure to validate these values as positive doubles You can ask the user for input here for the length of the other two sides (since you already have the base), or you can incorporate those values as private data fields to be initialized within the constructor(s). O Override toString (from the Shape class) to return super.toString() concatenated with the base, height and area of the shape. public class Rectangle{}: This is a direct child/subclass to Shape, and is described here. Private Data Field(s): O double length; O double width; O static int numRects=0; //to hold the number of rectangle objects created Methods O Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Rectangle and within the super class. o Getter/Setter methods: create methods to access and modify the private data fields O Override computeArea () to calculate the area of the triangle and return the value as a double As a reminder, the formula to calculate the area of a rectangle is: A-length*width Override compute Perimeter () to calculate the perimeter of the triangle and return the value as a double As a reminder, the formula to calculate the perimeter of a triangle is: P=(2*length) + (2*width) O Override toString (from the Shape class) to return super.toString() concatenated with the base, height and area of the shape. O public class ShapeTest{}: This class will include a main method to test the Shape, Circle and Triangle classes that you previously created. The main method you create should be simple enough to test your code, but also highlight the power of polymorphism, afforded through the use of object-oriented programming and inheritance. Your program should include a modularized main class (using methods) to do the following: An array of shapes that includes references to all types of concrete shape objects Allows the user to manually create a variety in the array O Be sure to validate any input, allowing the user to indicate what shape they are creating o Only one scanner should be used per program Randomly create shapes in the array (and pass in random values to constructors) Display each object, including the perimeter and area O You should use the toString() methods that you have overridden for this O Note that you do not have to explicitly invoke the toString method within a print statement. Display the total perimeter of all objects Display the total area of all objects Display the average perimeter and area for all Shapes. Suggestion: throughout this class (and the others that you create), add comments explaining the various concepts of OOP that you are utilizing. O Override toString (from the Shape class) to return super.toString() concatenated with the base, height and area of the shape. public class Rectangle{}: This is a direct child/subclass to Shape, and is described here. Private Data Field(s): O double length; O double width; O static int numRects=0; //to hold the number of rectangle objects created Methods O Constructor(s): overload the constructor method at least 3 times to initialize any combination of data fields from Rectangle and within the super class. o Getter/Setter methods: create methods to access and modify the private data fields O Override computeArea () to calculate the area of the triangle and return the value as a double As a reminder, the formula to calculate the area of a rectangle is: A-length*width Override compute Perimeter () to calculate the perimeter of the triangle and return the value as a double As a reminder, the formula to calculate the perimeter of a triangle is: P=(2*length) + (2*width) O Override toString (from the Shape class) to return super.toString() concatenated with the base, height and area of the shape. O public class ShapeTest{}: This class will include a main method to test the Shape, Circle and Triangle classes that you previously created. The main method you create should be simple enough to test your code, but also highlight the power of polymorphism, afforded through the use of object-oriented programming and inheritance. Your program should include a modularized main class (using methods) to do the following: An array of shapes that includes references to all types of concrete shape objects Allows the user to manually create a variety in the array O Be sure to validate any input, allowing the user to indicate what shape they are creating o Only one scanner should be used per program Randomly create shapes in the array (and pass in random values to constructors) Display each object, including the perimeter and area O You should use the toString() methods that you have overridden for this O Note that you do not have to explicitly invoke the toString method within a print statement. Display the total perimeter of all objects Display the total area of all objects Display the average perimeter and area for all Shapes. Suggestion: throughout this class (and the others that you create), add comments explaining the various concepts of OOP that you are utilizing.
Expert Answer:
Related Book For
Auditing A Business Risk Approach
ISBN: 978-0538476232
8th edition
Authors: Karla Johnstone, Audrey Gramling, Larry Rittenberg
Posted Date:
Students also viewed these programming questions
-
Total Word Count: 700 words (+ or 10%) excluding references. All students from every campus must complete this assessment online using the link provided and submit in Moodle through Turnitin This...
-
"I'm not sure we should lay out $300,000 for that automated welding machine," said Jim Alder, president of the Superior Equipment Company. "That's a lot of money, and it would cost us $84,000 for...
-
CST8333 Assignment 1 Project Initiation: Report & Presentation INSTRUCTIONS All material prepared for this assignment was produced by the author. Material from all third parties has been cited and...
-
Consider the following red-black tree. We perform the following sequence of insertions on this tree: 26, 37, 41, 23. Draw the tree after each operation of this sequence (Note that the operations are...
-
(a) Prove that a positive definite matrix has positive determinant: det K > 0. (b) Show that a positive definite matrix has positive trace: tr K >0. (c) Show that every 2 x 2 symmetric matrix with...
-
Direct Reading Gauges In your own words, "With regard to Mechanical Dial Indicators and Dial Test Indicators (lever type), how are they different? Also, how is "Amplification" achieved by each,...
-
Which type of audit involves a review of general and application controls, with a focus on determining if there is compliance with policies and adequate safe guarding of assets? a. information...
-
Nasreen Company issues $2 million, 10-year, 8% bonds at 97, with interest payable on July 1 and January 1. (a) Prepare the journal entry to record the sale of these bonds on January 1, 2014. (b)...
-
Explain the nature of the shrinking revenues from the airport's concessions.
-
Harper Morgan owns White Mountain Assessments in Laconia, New Hampshire. The standard workweek is 40 hours. For the weekly payroll ending September 9, 2022, checks dated September 14, 2022, complete...
-
A schematic representation of a vibration test rig is shown in Figure Q2.1, where m is a mass positioned between two springs of stiffness k. An electrical actuator provides the input displacement, x,...
-
Describe the impact to the organization if the change initiative is unsuccessful again, and potential steps the inter-professional team could take if the change is unsuccessful.
-
Suppose a sample of a certain substance decayed to 73.2% of its original amount after 300 days. (Round your answers to two decimal places.) (a) What is the half-life (in days) of this substance? days...
-
A line of positive charge is formed into a semicircle of radius R = 40.0 cm, as shown in the figure below. The charge per unit length along the semicircle is given by the expression = cos(0). The...
-
Why do bid and ask prices differ? 5. How do market makers determine bid-ask spreads? 6. What is the role of bid-ask spreads in market liquidity?
-
Estimate the distance you can travel in 7 hours 55 mins if u drive an average of 41 miles per hour. round to the mile
-
Is there value in sweat equity or the owner's involvement in a company to help fund a business?
-
After Theorem 1.5 we note that multiplying a row by 0 is not allowed because that could change a solution set. Give an example of a system with solution set S0 where after multiplying a row by 0 the...
-
Assume that the auditor's tests of internal controls did not reveal any material weaknesses in controls. However, during the audit, a material misstatement in an important account was found. Does the...
-
Keune and Keune, CPAs, a regional audit firm with most of its activities located in one state, just accepted a new privately held company as an audit client. The company is considered a plum because...
-
You are a senior auditor working for Rittenberg & Schwieger, CPAs. Your staff assistant has drafted the following audit report of a publicly traded U.S. company. You believe the scope limitation is...
-
On December 31, 2017, Phillip (Appendix 10A) Company issued \(\$ 600,000\) of ten-year, nine percent bonds payable for \(\$ 496,771\), yielding an effective interest rate of twelve percent. Interest...
-
On December 31, 2017, Karen Company issued \(\$ 400,000\) of 10 -year, ten percent bonds payable for \(\$ 454,361\), yielding an effective interest rate of eight percent. Interest is payable...
-
On January 1, Lorraine, Inc., entered into a lease contract. The lease contract was a ten-year lease for a computer with \(\$ 15,000\) annual lease payments due at the end of each year. Lorraine took...
Study smarter with the SolutionInn App