Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write code please CS 251 Lab Exercise 03 Main topics Writing Classes Declaring /Using Instance Variables Writing Instance Methods Accessors and Mutators public vs private

write code please image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
CS 251 Lab Exercise 03 Main topics Writing Classes Declaring /Using Instance Variables Writing Instance Methods Accessors and Mutators public vs private Constructors static vs non-static Exercise This week we will be practicing writing a complete" eles, starting from where you left off last week, which includes all of the standard mutators as well as an instance count. In addition careful attention to the public, private and static specifiers will be made. Getting Started to start this exercise, you should: 1. Open eclipse and start a new Java project named tabo3 2. Add a Cluss (named Circle) to this project, and copy the contents of the Circle file provided into it. 3. Add a Cles (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 in its radius This class is not complete and must be modified as such 1. All class variables mat 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 close() method so that it makes use of the copy constructor, instead of using the default constructor, followed by the rest() method. Circle Driver.java A simple driver close to test the Circle class. This class is not complete and trust 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. Once you have completed the requirements: 1. Make sure that your program runs without errors or warnings 2. Run your program enough times to verify its correctness. 3. If it runs correctly, then see your TA for a check-off. public class Circle { private double radius; public double getRadius() [ return this.radius; } private void setRadius(double radius) { if (radius > 0) this.radius = radius; else this.radius = 0; 3 public void resize(double newRadius) this.setRadius(newRadius); ) public Circle clone) Circle c = new Circle(); c. resize(this.getRadius()); return ci } public boolean equals(Circle guest) return guest.getRadius() == this.getRadius(); 3 public void print) System.out.print("The circlel's radius is " + this.getRadius()); 1 3 MacBook Air public class Circlebriver { public static void main(String[] args) C Scanner stdin = new Scanner(System.in); Circle big new Circle(); Circle small = new Circle(); System.out.println(""); System.out.print("Big"); big.print(); System.out.println(""); System.out.print("Small : "); small.print() System.out.println(" "); double bigRadius; System.out.print("Enter the radius of a big circle: "); bigRadius = stdin.nextDouble(); big.resize(bigRadius); double smallRadius: System.out.print("Enter the radius of small circle: "); snal Radius = stdin.nextDouble(); small.resize(smallRadius); System.out.println(""); System.out.print("Big : "); big.print(); System.out.println(""); System.out.print("Smail : "); Small.print(); System.out.println(""); if (big.equals(small)) System.out.println(" big equals shall "); else System.out.println(" big does not equals small "); System.out.println(""); Circle bigcopy-big.ctone(); System.out.print("Big Copy : "); bigcopy.print(); System.out.println() MacBook Air ** 80 DO B000 FS 0% System.out.println(""); if (bigcopy.equals(big)) System.out.println(" bigcopy equals big "); else System.out.println(" bigcopy does not equals big "); System.out.println(""); 3 >

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

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions