
Implement all the classes using Java
Note: This problem requires you to submit just two classes: Circle.java, Cylinder.java.
Do NOT include "public static void main()" method inside all of these classes.
In this exercise, a subclass called Cylinder is derived from the superclass Circle as shown in the class diagram (where an arrow pointing up from the subclass to its superclass). Study how the subclass Cylinder invokes the superclass' constructors (via super() and super(radius)) and inherits the variables and methods from the superclass Circle.
You can reuse the Circle class that you have created in the previous exercise. Make sure that you keep "Circle.class" in the same directory.
Method Overriding and "Super": The subclass Cylinder inherits getArea() method from its superclass Circle. Try overriding the getArea() method in the subclass Cylinder to compute the surface area (=π×radius×radius×height) of the cylinder instead of the base area. That is, if getArea() is called by a Circle instance, it returns the area. If getArea() is called by a Cylinder instance, it returns the surface area of the cylinder.
If you override the getArea() in the subclass Cylinder, the getVolume() no longer works. This is because the getVolume() uses the overridden getArea() method found in the same class. (Java runtime will search the superclass only if it cannot locate the method in this class). Fix the getVolume().
Hints: After overriding the getArea() in subclass Cylinder, you can choose to invoke the getArea() of the superclass Circle by calling super.getArea().
TRY: Provide a toString() method to the Cylinder class, which overrides the toString() inherited from the superclass Circle, e.g.,
Try out the toString() method in TestCylinder.
Note: @Override is known as an annotation (introduced in JDK 1.5), which asks the compiler to check whether there is such a method in the superclass to be overridden. This helps greatly if you misspell the name of the toString(). If @Override is not used and toString() is misspelled as ToString(), it will be treated as a new method in the subclass, instead of overriding the superclass. If @Override is used, the compiler will signal an error. @Override annotation is optional but certainly nice to have.
![Circle
-radius:double = 1.0
-color:String = "red"
%3D
+Circle()
+Circle(radius: double)
+Circle(radius:double,color:String)
+getRadius (): double
+setRadius (radius:double):void
+getColor():String
+setColor(color:String):void
+getArea(): double
+tostring():String.
"Circle[radius=r,color=c]"
superclass
subclass
extends
Cylinder
-height:double = 1.0
+Cylinder()
+Cylinder(radius:double)
+Cylinder(radius:double, height:double)
+Cylinder (radius:double, height:double,
color:String)
+getHeight():double
+setHeight (height:double):void
+getVolume (): double](https://content.bartleby.com/qna-images/question/f3dad014-c6bb-4735-812f-053559c6a885/7c6cfd7e-da66-4e28-8f80-0046586e554e/b28n6wg_thumbnail.jpeg)

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images

- class Cow: de f init (self): self.other = None w1 = Cow () wl.other Cow () Given the python code above, draw 2 different class diagrams and 2 different object diagrams that matches to the code and briefly explain on the diagrams.arrow_forwardIn your code, you have a method that takes a superclass instance as a mandatory argument. An instance of a subclass, rather than a superclass object, will suffice. Can we do that, if so? Where is the value in that?arrow_forwardImplement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit only one class: Ball.java. Do NOT include "public static void main()" method inside all of these classes. Graders will be testing your classes, using the unit-testing framework JUnit 4. A class called Ball is designed as shown in the class diagram. The Ball class contains the following private instance variables: x, y and radius, which represent the ball's center (x, y) co-ordinates and the radius, respectively. xDelta (Δx) and yDelta (Δy), which represent the displacement (movement) per step, in the x and y direction respectively. The Ball class contains the following public methods: A constructor which accepts x, y, radius, speed, and direction as arguments. For user friendliness, user specifies speed (in pixels per step) and direction (in degrees in the range of (-180°, 180°]). For the internal operations, the speed and direction are to be…arrow_forward
- This way, any class that implements the Visible interface can define its own behavior for making an object visible or invisible based on its specific requirements.Create a Priority Java interface with two methods: setPriority and getPriority. The interface should define a method for assigning numerical priority to a group of objects. Create a class named Task that represents a task (such as one on a to-do list) that implements the Priority interface. Make a driver class to test certain Task objects.arrow_forwardJava ProgramWrite the FullName class to be a subclass of Name, so that it also stores a middle name. It needs a constructor and a toString() method. Make sure:FullName class definition as described aboveInstantiating a FullName object from the new mayor's name entered by the user, and adding that object to the mayorListInputting the names from mayors.txtInstantiating a FullName object for each of those names from the file and adding them to the mayorListUsing exception handling to catch errors that might occur in file i/o: your program should catch all exceptions. Your main method should not have a "throws" clause. Other methods may throw exceptions, as long as the main method catches them. Code:import java.io.*;import java.util.*; class Main { public static void main(String[] args) { Scanner inFile = null, keyboard; String first, middle, last; ArrayList<FullName> mayorList = new ArrayList<FullName>(); keyboard = new Scanner(System.in);…arrow_forward1. We have to calculate the area of a rectangle, a square and a circle. Create an abstract class 'Shape' with three abstract methods namely 'RectangleArea' taking two parameters, 'SquareArea' and 'CircleArea' taking one parameter each. The parameters of 'RectangleArea' are its length and breadth, that of 'SquareArea' is its side and that of 'CircleArea' is its radius. Now create another class 'Area' containing all the three methods 'RectangleArea', 'SquareArea' and 'CircleArea' for printing the area of rectangle, square and circle respectively. Create an object of class 'Area' and call all the three methods. 2. Repeat the above question for 4 rectangles, 4 squares and 5 circles. Hint- Use array of objects.arrow_forward
- This is the question: Design and implement a class called Bug, which represents a bug moving along a horizontal wire. The bug can only move for one unit of distance at a time, in the direction it is facing. The bug can also turn to reverse direction. For your design, create a UML Class diagram similar to Figure 5.5 on page 180 of the textbook. Note that you need to include the constructor in the methods section if you code a constructor. Bug will require a toString method to return the current position and which direction the bug is facing to the driver so it can be output.Hint: Remember that a horizontal line has a zero position in the middle with positive to the right and negative to theleft. Consider that a bug will land on the wire at some point before starting along the wire.Write an interactive test driver that instantiates a Bug, then allows the user to manipulate it with simple commands like Output (to see the position and direction), Move, Turn, Exit ... single letters work…arrow_forwardWrite an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for getting information such as the volume and the surface area of a three-dimensional shape. Then make classes and subclasses that implement various shapes such as cube, cylinders and spheres. Place common behavior in superclasses whenever possible, and use abstract classes as appropriate. Add methods to the subclasses to represent the unique behavior of each three-dimensional shape, such as a method to get a sphere’s radius. Select three shapes from the list: sphere, cube, tetrahedron, cone, cylinder and rectangular prisms.arrow_forwardI'm learning java in college and I missed one homework assignment. Since then it has been difficult to keep up with homework because they were based on the one I missed. Here's the prompt: Design a class Phone with one data member as long phoneNumber. Add constructors, get/set methods to class Phone. Then design a class InternationalPhone as subclass of class Phone, with one extra data member as int countryCode. Add constructors, get/set methods to class InternationalPhone. Write a main program to test these two classes. (We use netbeans btw) I can't get any credit for this so there's no rush but I would be very happy to recieve an answer before the end of the semester. Thank you in advance :)arrow_forward
- Make sure you know the difference between an abstract class and an interface and constructors.arrow_forwardB elow for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forwardelow for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





