Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me code the following in: JAVA Please use many COMMENTS and read the task THOROUGHLY Full points will be awarded, thanks in advance!
Please help me code the following in: JAVA
Please use many COMMENTS and read the task THOROUGHLY
Full points will be awarded, thanks in advance!
Shape class: Spray class: PolyDemo class:
Your class will start with the line "public Circle extends Shape" and this will only compile if Shape.java is also in the same working directory (or project) when compiling As a Circle, you will need to add more data and methods that are custom to being a Circle; these are specifics that not just any shape would have, such as a radius data item and a getRadius() accessor function Circle Extends Shape The first thing we need to do is download the Shape superclass, the Spray subclass, and the driver PolyDemo.java. This should compile and run with no modifications, but will only display a set of "spray" shapes on the screen (which are ovals that randomly change their width and height). You will create two subclasses of Shape (just like Spray) in the following steps (1) Download all the files and put them into one project (2) Run the PolyDemo.java and observe the output. (3) Build a new class called "Circle" using the inheritance keyword "extends" a. "public class Circle extends Shape" (4) Override the getArea() method a. This method should return a double corresponding to the area of your shape (5) Override the draw() method a. This method will draw the shape onto the Graphics context g (or g2D) i. Look at Spray for an example of how to do this, or try 1. g.draw3DRect(x,y,width,height, raised) 2. g.drawOval(x,y,width,height) (6) Next, define members that are custom to Circles, such as a. private double radius; b. double getRadius); c. void setRadius(double); (7) Modifying the PolyDemo function getRandShape() so that it can create and return objects of your new Circle class Do this by replacing one of the switch cases that state "retVal- new Spray()" with "retVal- new Circle()". a. (8) Run the PolyDemo.java and observe your new Circle subclass also being rendered to the screen Your class will start with the line "public Circle extends Shape" and this will only compile if Shape.java is also in the same working directory (or project) when compiling As a Circle, you will need to add more data and methods that are custom to being a Circle; these are specifics that not just any shape would have, such as a radius data item and a getRadius() accessor function Circle Extends Shape The first thing we need to do is download the Shape superclass, the Spray subclass, and the driver PolyDemo.java. This should compile and run with no modifications, but will only display a set of "spray" shapes on the screen (which are ovals that randomly change their width and height). You will create two subclasses of Shape (just like Spray) in the following steps (1) Download all the files and put them into one project (2) Run the PolyDemo.java and observe the output. (3) Build a new class called "Circle" using the inheritance keyword "extends" a. "public class Circle extends Shape" (4) Override the getArea() method a. This method should return a double corresponding to the area of your shape (5) Override the draw() method a. This method will draw the shape onto the Graphics context g (or g2D) i. Look at Spray for an example of how to do this, or try 1. g.draw3DRect(x,y,width,height, raised) 2. g.drawOval(x,y,width,height) (6) Next, define members that are custom to Circles, such as a. private double radius; b. double getRadius); c. void setRadius(double); (7) Modifying the PolyDemo function getRandShape() so that it can create and return objects of your new Circle class Do this by replacing one of the switch cases that state "retVal- new Spray()" with "retVal- new Circle()". a. (8) Run the PolyDemo.java and observe your new Circle subclass also being rendered to the screenStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started