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
-
"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...
-
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...
-
Set up a horizontal model in the following format: Required: a. Enter the beginning (July 28, 2013) and ending (August 3, 2014) account balances for Accounts Receivable, Inventories, and Payable to...
-
explain the concept of mortgage-backed securities (MBS) and their role in providing liquidity to the mortgage market, while addressing the potential systemic risks associated with their proliferation...
-
The 2011 annual report of Priority Parcel Service (PPS) reported revenue of \($28\) billion. Total expenses for the year were \($21\) billion. PPS ended the year with total assets of \($37\) billion,...
-
Finding Financial Information Refer to the financial statements of American Eagle given in Appendix B at the end of this book. Required: 1. What is the amount of accrued compensation and payroll...
-
Please complete the answers in the charts format? The following information pertains to Flaxman Manufacturing Company for April. Assume actual overhead equaled applied overhead. April 1 Inventory...
-
Ryan and Blake Lively are married filing jointly taxpayers. Ryan's birthdate is August 10, 1982 and Social Security number is 434-14-4448. Blake's birthdate is March 19, 1983 and their Social...
-
Discuss what is meant to empower employees and how are policies related to the idea of empowerment. In addition, would you think initiatives of empowerment work well within an environment which is...
-
how would I do what's in the highlighted area Your supervisor has asked you to complete a two-part project. The first part involves joining ServerSA1 to the company Active Directory domain, and the...
-
Company Z is looking at potentially introducing a new product, and has compiled the following annual estimates: Revenue: $ 3 0 , 0 0 0 Fixed Costs: $ 1 8 , 0 0 0 ...
-
1. Recall the "falling chain" problem from class and assume the chain to have length X and mass m. Y 9 In terms of the distance y, the chain's kinetic energy and potential energy are given by m 47 (A...
-
The following table shows the crude steel production in the USA, in millions of metric tons. Year Crude Steel Production 1980 0 80 1988 8 92 91 1991 11 (A) Find a quadratic function f(x) = ax2 + bx +...
-
Write C++ program that accepts coefficients of a quadratic equation from the user and displays the roots. The form of the quadratic equation is: y = ax +bx+c In this task we will assume that the...
-
Quorum Industries manufactures Bluetooth headphones. The company applies fixed manufacturing overhead based on standard direct labour hours. The following information relates to the company's...
-
Suppose that A is an m n matrix with linearly independent columns and the linear system LS(A, b) is consistent. Show that this system has a unique solution.
-
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...
-
The flow about a \(150 \mathrm{~mm}\) artillery projectile which travels at \(600 \mathrm{~m} / \mathrm{s}\) through still air at \(30^{\circ} \mathrm{C}\) and absolute pressure \(101.4...
-
Consider water flow around a circular cylinder, of diameter \(D\) and length \(l\). In addition to geometry, the drag force is known to depend on liquid speed, \(V\), density, \(ho\), and viscosity,...
-
A 1:10 scale model of a tractor-trailer rig is tested in a wind tunnel. The model frontal area is \(A_{m}=0.1 \mathrm{~m}^{2}\). When tested at \(V_{m}=75 \mathrm{~m} / \mathrm{s}\) in standard air,...
Study smarter with the SolutionInn App