Concept explainers
Explanation of Solution
Adding “equals()” method to “Rectangle”, “Circle” and “Triangle” class:
//Definition of method equals() for Rectangle class
public boolean equals(Object obj)
{
//Check whether "obj" is the instance of Rectangle
if (obj instanceof Rectangle)
{
//Create an object "rectVal" to Rectangle
Rectangle rectVal = (Rectangle) obj;
//Return the width and height
return width == rectVal.width && height == rectVal.height;
}
//Otherwise, the width and height is not valid
else
{
//Then return the value false
return false;
}
}
//Definition of method equals() for Circle Class
public boolean equals(Object obj)
{
//Check whether "obj" is the instance of Cicle
if (obj instanceof Circle)
{
//Create an object "cirVal" to Circle
Rectangle cirVal = (Circle) obj;
//Assign and return the radisu
return radius == cirVal.radius;
}
//Otherwise, the value of radius not valid
else
{
//Then return the value false
return false;
}
}
//Definition of method equals() for Triangle class
public boolean equals(Object obj)
{
//Check whether "obj" is the instance of Triangle
if (obj instanceof Triangle)
{
//Create an object "triVal" to Rectangle
Triangle triVal = (Triangle) obj;
//Assign and return the a, b and c
return a == triVal...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
EBK BUILDING JAVA PROGRAMS
- 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