Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm just a bit confused about the constructors: the default, specifying, and copy. I'm not sure if I did it right, please explain the difference

I'm just a bit confused about the constructors: the default, specifying, and copy. I'm not sure if I did it right, please explain the difference of each. Thank you!
The problem and given codes: image text in transcribed
image text in transcribed
image text in transcribed
My code:
image text in transcribed
1. Open eclipse and start a new Java project named Labo3 2. Add a Class (named Circle) to this project, and copy the contents of the Circle file provided into it. 3. Add a Class (named CircleDriver) to this project, and copy the contents of the CircleDriver file provided into it Requirements Circle.java A simple class which models a circle by its one defining characteristic, which is its radius. This class is not complete and must be modified as such: 1. All class variables must be private 2. The initial instance count must be 0 3. Include a public accessor for the instance count 4. Include a public mutator for the instance count 5. By default all instances have a radius of 1.0 6. Include the standard default constructor All access of instance data by this constructor must be made via the the specifying constructor. 7. Include the standard specifying constructor All access of class and instance data by this constructor must be made via the accessors and mutators. 8. Include the standard copy constructor All access of instance data by this constructor must be made via the the specifying constructor. 9. Modify the Circle clone() method so that it makes use of the copy constructor, instead of using the default constructor, followed by the resize() method. CircleDriver.java A simple driver class to test the Circle class. This class is not complete and must be modified as such: 1. Add / modify lines of code and "test" that each of your constructors are functioning properly. 2. Add / modify lines of code and "test" that your instance count is being maintained properly. oublic class Circle /Al1 class variables must be private //The initial instance count must be 0 private double radius; private int count =0; //Include a public accessor for the instance count public int getcount () f return this. count; 1. / Include a public mutator for the instance count public void setcount (int count) f this. count = count: 1 6. Include the standard default constructor. public circle() ( this. countt+; this. radius =1.0; /IInclude the standard specifying constructor public circle (double radius) 1 setRadius (radius); setcount (t+count): I / Include the standard copy constructor public circle (Circle c) i setradius (c.radius) il \} public double getradius () i. return this.radius; 3 private void setRadius (double radius) 1 if (radius >=0 ) this. radius = radius; else

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Understand why empowerment is so important in many frontline jobs.

Answered: 1 week ago