Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lah assianment vo I are asked to write iava code of nverridden ecusals() and to.Strina() methnds - Use the classes you created in
In this lah assianment vo I are asked to write iava code of nverridden ecusals() and to.Strina() methnds - Use the classes you created in the first assignment. - equals() method instructions: - Override the equals() method of for each class, - for each implementation of the method, it has the following line to print out the name of the class System.out.println(this.getClass().getSimpleName()+ " equals method is invoked"); - each method accepts object as parameter - public boolean equals(0bject o) - At first, check that if the object is null then return false - Compare the class type of the parameter object and your class type, if they are different then return false. You can get your class type using: this.getClass() - Create a new instance of your class and assign the parameter object to this variable. Do the type conversion of parameter object to your class type using casting. Compare: Exp: Circle v=( Circle) 0 ; - For circle object: radius and color - For cylinder object: radius, color, and height - For curve object: radius, color, and angle if they are same, then return true, otherwise false. Do not forget, the color the color attribute is String and requires string comparison. - toString() method instructions: - Override the toString() method for each class, - The method returns the following values, having tab space between each value: - For circle object: radius and color - For cylinder object: radius, color, and height - For curve object: radius, color, and angle - You are given testlnheritance2.java file. Use this class to evaluate your code. You should receive the following output when the main method is called. Expected Code: Circle equals method is invoked true Circle equals method is invoked false Curve equals method is invoked true Curve equals method is invoked false Cylinder equals method is invoked true Cylinder equals method is invoked false 5.0 5.0 Red 5.03.0 Red 6.0 In this lah assianment vo I are asked to write iava code of nverridden ecusals() and to.Strina() methnds - Use the classes you created in the first assignment. - equals() method instructions: - Override the equals() method of for each class, - for each implementation of the method, it has the following line to print out the name of the class System.out.println(this.getClass().getSimpleName()+ " equals method is invoked"); - each method accepts object as parameter - public boolean equals(0bject o) - At first, check that if the object is null then return false - Compare the class type of the parameter object and your class type, if they are different then return false. You can get your class type using: this.getClass() - Create a new instance of your class and assign the parameter object to this variable. Do the type conversion of parameter object to your class type using casting. Compare: Exp: Circle v=( Circle) 0 ; - For circle object: radius and color - For cylinder object: radius, color, and height - For curve object: radius, color, and angle if they are same, then return true, otherwise false. Do not forget, the color the color attribute is String and requires string comparison. - toString() method instructions: - Override the toString() method for each class, - The method returns the following values, having tab space between each value: - For circle object: radius and color - For cylinder object: radius, color, and height - For curve object: radius, color, and angle - You are given testlnheritance2.java file. Use this class to evaluate your code. You should receive the following output when the main method is called. Expected Code: Circle equals method is invoked true Circle equals method is invoked false Curve equals method is invoked true Curve equals method is invoked false Cylinder equals method is invoked true Cylinder equals method is invoked false 5.0 5.0 Red 5.03.0 Red 6.0
Step 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