Question

Program 1 Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for g

THIS IS IN THE JAVA SCRIPT CODE

ALSO PLEASE SEND ME THE CODE TYPED THANK YOU.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Methods.java

public interface Methods {

   double getArea();
   double getVolume();
}

Shape.java

public abstract class Shape implements Methods {

   int param;

   public Shape(int param) {
       super();
       this.param = param;
   }

   public int getParam() {
       return param;
   }

   public void setParam(int param) {
       this.param = param;
   }

   @Override
   public String toString() {
       return "Shape [Dimension=" + param + "]";
   }
  
  
  

Sphere.java

public class Sphere extends Shape{

   public Sphere(int param) {
       super(param);
       // TODO Auto-generated constructor stub
   }

   @Override
   public double getArea() {
       // TODO Auto-generated method stub
       return 4*Math.PI*Math.pow(this.param,2);
   }

   @Override
   public double getVolume() {
       // TODO Auto-generated method stub
       return 4*Math.PI*Math.pow(this.param,3)/3;
   }
  
   @Override
   public String toString() {
       return "Sphere [Radius: " + param + ", Area: "+this.getArea()+", Volume: "+this.getVolume()+"]";
   }

}

Cylinder.java

public class Cylinder extends Shape {
  
   int height;

   public Cylinder(int radius,int height) {
       super(radius);
       // TODO Auto-generated constructor stub
       this.height = height;
   }

   @Override
   public double getArea() {
       // TODO Auto-generated method stub
       return 2*Math.PI*this.param*(this.param+this.height);
   }

   @Override
   public double getVolume() {
       // TODO Auto-generated method stub
       return Math.PI*Math.pow(this.param, 2)*this.height;
   }
  
   @Override
   public String toString() {
       return "Cylinder [Radius: " + param + ", Height: "+this.height+", Area: "+this.getArea()+", Volume: "+this.getVolume()+"]";
   }

}

Cube.java

public class Cube extends Shape{

   public Cube(int param) {
       super(param);
       // TODO Auto-generated constructor stub
   }

   @Override
   public double getArea() {
       // TODO Auto-generated method stub
       return 6*Math.pow(this.param,2);
   }

  
   public double getVolume() {
       // TODO Auto-generated method stub
       return Math.pow(this.param,3);
   }
  
   @Override
   public String toString() {
       return "Cube [Edge: " + param + ", Area: "+this.getArea()+", Volume: "+this.getVolume()+"]";
   }

}

ShapeTester.java

public class ShapeTester {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Shape[] shapes = new Shape[3];
      
       shapes[0] = new Sphere(5);
       shapes[1] = new Cube(5);
       shapes[2] = new Cylinder(5,3);
      
       for(Shape s : shapes)
           System.out.println(s);
   }

}

Output

Sphere [Radius: 5, Area: 314.1592653589793, Volume: 523.5987755982989]
Cube [Edge: 5, Area: 150.0, Volume: 125.0]
Cylinder [Radius: 5, Height: 3, Area: 251.32741228718345, Volume: 235.61944901923448]

Screenshot

Shape Tester.java X Cylinder.java D Cube.java Methods.java Shape.java Sphere.java 1 package march1; 3 public class ShapeTeste

Add a comment
Know the answer?
Add Answer to:
THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you...

    Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...

  • Please help me code the following in: JAVA Please create the code in as basic way...

    Please help me code the following in: JAVA Please create the code in as basic way as possible, so I can understand it better :) Full points will be awarded, thanks in advance! Program Description Write a program that demonstrates the skills we've learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can...

  • Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me e...

    Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me errors. Thanks in advance!! This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. (2 pts) item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of...

  • JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST...

    JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST CASES(WHAT IM TRYING TO PRODUCE) BELOW THOSE IMAGES ARE THE .JAVA FILES THAT I HAVE CREATED. THESE ARE GeometircObject.Java,Point.java, and Tester.Java. I just need help making the Rectangle.java and Rectangle2D.java classes. GeometricObject.Java: public abstract class GeometricObject { private String color = "white"; // shape color private boolean filled; // fill status protected GeometricObject() { // POST: default shape is unfilled blue this.color = "blue";...

  • I NEED HELP with this. please create a UML diagram. I need a simple code to...

    I NEED HELP with this. please create a UML diagram. I need a simple code to solve the problem.   The ADT Bag is a group of items, much like what you might have with a bag of groceries. In a software development cycle, specification, design, implementation, test/debug, and documentation are typical activities. The details are provided in the rest of the document. ADT Bag Specification: (Note: You should not change the names of the operations in your program. This should...

  • ***Java Project*** Please upload the entire code and attach the screenshots of the code. The screenshots help me to write the code, so please attach that. Thank you so much. If you could use the comme...

    ***Java Project*** Please upload the entire code and attach the screenshots of the code. The screenshots help me to write the code, so please attach that. Thank you so much. If you could use the comment to explain the code, it would be perfect! Thank you so much~ Design and code a Swing GUl for a two-player tic-tac-toe (noughts and crosses) game on a 3 x 3 game board. The JFrame should use a BorderLayout with a JLabel in the...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • i need this in java code and wiht comments thanks You are give the following interface...

    i need this in java code and wiht comments thanks You are give the following interface Movable: public interface Movable public void move forward(); public void move Backward(); public void stop(); public void moveLeft() public void moveRight(); ) Base on the Movable interface create three classes: Caro), Plane(), and Ship that implement it. After that, create a program that will polymorphically process an array of Movable by calling each of the interface methods, after creating an object for each one...

  • This question is about java program. Please show the output and the detail code and comment.And...

    This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT