Java In the following Point class create the toString() method (as you know the toString() method is used in the System

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Java In the following Point class create the toString() method (as you know the toString() method is used in the System

Post by answerhappygod »

Java
In the following Point class
create the toString() method (as you know the toString()method is used in the System.out.println() calls when you areprinting an object not necessarily a String)
in main() method
-- using the constructor create a new point p=(2,3) -- create a copy of p using p.getLocation() -- two other tasks are described with comments within thecode below
The incomplete main() for the Point classand the corresponding output is included below
Output:
2. Consider the subclass ColoredPoint (below) whichextends Point.
--Complete the toString() method which returns a Stringproviding info about your object (to be used in yourSystem.out.println() method) --Complete the new methods such as setColor() and getColor()(as indicated with "code here").--Complete the two constructors , noteyou will need the keyword super which refers to thesuperclass constructor
The complete main() and the corresponding output is shownbelow
Output:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply