PLEASE HELP this is the last part of my lab and I need help ): add comments please (: if it is too difficult you do not have to do part 3 but it would be greatly appreciated if you do ! Obtain example code files Circle.java, Shape.java, CircleShape2.java, Sphere.java, and CircleShapeApp.java from the downloaded files in Ch8. Compile and execute the example and understand the polymorphism it performs. (I have copied and pasted all of these files below) Modify the application as follows: Code a class called Cone inherited from class Circle. Cone will override the computeArea() and computeVolume() methods from its superclass to calculate the area and volume of a Cone object. Must apply code-reusability in the calculation formula. Modify the driver code, CircleShapeApp.java, so it will also create an object of Cone with a height of 12.5 and diameter of 10.48. Modify the polymorphic calls to calculate and display the result of the calculations. Instead of hard-coded data, modify your application to be interactive using JOptionPane, thus it will ask user to enter proper data for different object, continue to utilize the Validator class you have developed before to validate all wrong data entries, including negative and non-numerical data. Your program must continue to run until the user enters “n” to terminate the execution. You must also validate the user's entry so that only “y” and “n” are accepted. ----- Circle.java ----- //subclass class Circle public class Circle extends CircleShape2{ protected double area; protected double volume; public Circle() { super(); //call super class non-argument constructor area = 0; volume = 0; } public Circle(double radius) { super(radius); //call super class one-argument constructor } public Circle(double x1, double y1, double x2, double y2) { super(x1, y1, x2, y2);//call super class four-argument constructor } public void computeArea() { area = Math.PI * radius * radius; } public double getArea() { return area; } public void computeVolume() {} //must implement public double getVolume() { return volume; } public String toString() { //override the toString() method return super.toString() + "Area: " + area + "\n"; } } ----- Shape.java ----- //abstract class Shape public abstract class Shape { protected double x1, y1, x2, y2; public Shape() { x1 = y1 = x2 = y2 = 0.0; } public Shape(double x1, double y1, double x2, double y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } public String toString() { String message = "(" + x1 + "," + y1 + "), (" + x2 + "," + y2 + ")\n"; return message; } public abstract void computeArea(); //¶¨Òå³éÏó·½·¨ public abstract void computeVolume(); public abstract double getArea(); public abstract double getVolume(); } ----- CircleShape2 ----- //abstract class CircleShape2 public abstract class CircleShape2 extends Shape { //Inheritance protected double radius; public CircleShape2() { x1 = y1 = x2 = y2 = 0.0; } public CircleShape2(double x1, double y1, double x2, double y2) { super(x1, y1, x2, y2); //Call constructor of Shape } public CircleShape2(double radius) { this.radius = radius; } public void setRadius(double radius) { this.radius = radius; } public double getRadius() { return radius; } public void computeRadius() { radius = Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2) * (y1 - y2)); } public String toString() { return super.toString() + "Radius: " + radius + "\n"; } } ----- Sphere.java ----- //subclass class Sphere inherites Circle class Sphere extends Circle{ public Sphere() { super(); //call super class non-argument constructor } public Sphere(double radius) { super(radius); //call super class one-argument constructor } public Sphere(double x1, double y1, double x2, double y2) { super(x1, y1, x2, y2);//call super class four-argument constructor } public void computeArea() { //compute sphere's area super.computeArea(); //call super class' method area = 4* area; } public void computeVolume() { //compute sphere's valume super.computeArea(); volume = 4.0/3 * radius * area; } } ----- CircleShapeApp.java ----- //the driver class for circle shapes public class CircleShapeApp{ public static void main(String[] args) { Circle circle = new Circle(12.98); Sphere sphere = new Sphere(25.55); Shape shape = circle; shape.computeArea(); System.out.println("circle area: " + shape.getArea()); shape.computeVolume(); System.out.println("circle volume: " + shape.getVolume()); shape = sphere; shape.computeArea(); System.out.println("Sphere area: " + shape.getArea()); shape.computeVolume(); System.out.println("Sphere volume: " + shape.getVolume()); } }


Are there any questions left?
New questions in the section Engineering
Sign up for the IQClass
Answers from experts with no ads!
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Made with love
This website uses cookies to make IQClass work for you. By using this site, you agree to our cookie policy

Pleased to see you again

IQClass unlocks the learning potential of every child
  • Master useful skills
  • Improve learning outcomes
  • Share your knowledge
Create an account
Sign in
Recover lost password
Or log in with

Create an account

IQClass unlocks the learning potential of every child
  • Master useful skills
  • Improve learning outcomes
  • Share your knowledge
Create an account
Sign Up
Or sign up with
By signing up, you agree to the Terms of use and Privacy policy.
Looking for an answer to a question you need help with?
you have баллов