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

write code please 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" class, 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 eclipee and start a new Java project namned Labos 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 ruditus of 10 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. Circle Driver.java A simple driver class to test the Circle class. This class is not complete and must be modified as such: U public class Circle C private double radius; public double get Radius() { return this.radius; ) private void set Radius (double radius) { if (radius > 0) this.radius = radius; else this.radius = 0; ) public void resize(double newRadius) { this.setRadius(newadius); ) public Circle clone) ( Circle new Circle(); c.resize(this.getRadius()); return c; 3 public boolean equals(Circle quest) { return guest.getRadius() ww this.getRadius(); } public void print() System.out.print("The circlel's radius is. this.getRadius(); nya import java.util.Scanner; public class CircleDriver { 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("Snail : "); small.print(); System.out.println(" "); double bigRadius; Systen.out.print("Enter the radius of a big circle : "); bigRadius = stdin.nextDouble(); big.resize(bigRadius); double small Radius; System.out.print("Enter the radius of small circle : "); smallRadius = stdin.nextDouble(); small.resize(SmallRadius); System.out.println(""); System.out.print("Big : "); big.print(); System.out.println(""); System.out.print("Small : "); small.print(); System.out.println(""); if (big.equals(small)) System.out.println(" big equals small "); else System.out.println(" big does not equals small "); System.out.println(""); Circle bigcopy = big.clone(); System.out.print("Bigcopy :): bigcopy.print(); System.out.println(""); if (bigcopy.equals(big)) System.out.printin( bigcopy equals big "); else System.out.println(" bigcopy does not equals big "); System.out.println(""); 2 acs Instructure.com/1/sessions/eyJhbGCIOLIUZUxMiL.BAPCSK7395lwEec_aasw64FTYTO 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" class, 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 eclipee and start a new Java project namned Labos 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 ruditus of 10 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. Circle Driver.java A simple driver class to test the Circle class. This class is not complete and must be modified as such: U public class Circle C private double radius; public double get Radius() { return this.radius; ) private void set Radius (double radius) { if (radius > 0) this.radius = radius; else this.radius = 0; ) public void resize(double newRadius) { this.setRadius(newadius); ) public Circle clone) ( Circle new Circle(); c.resize(this.getRadius()); return c; 3 public boolean equals(Circle quest) { return guest.getRadius() ww this.getRadius(); } public void print() System.out.print("The circlel's radius is. this.getRadius(); nya import java.util.Scanner; public class CircleDriver { 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("Snail : "); small.print(); System.out.println(" "); double bigRadius; Systen.out.print("Enter the radius of a big circle : "); bigRadius = stdin.nextDouble(); big.resize(bigRadius); double small Radius; System.out.print("Enter the radius of small circle : "); smallRadius = stdin.nextDouble(); small.resize(SmallRadius); System.out.println(""); System.out.print("Big : "); big.print(); System.out.println(""); System.out.print("Small : "); small.print(); System.out.println(""); if (big.equals(small)) System.out.println(" big equals small "); else System.out.println(" big does not equals small "); System.out.println(""); Circle bigcopy = big.clone(); System.out.print("Bigcopy :): bigcopy.print(); System.out.println(""); if (bigcopy.equals(big)) System.out.printin( bigcopy equals big "); else System.out.println(" bigcopy does not equals big "); System.out.println(""); 2 acs Instructure.com/1/sessions/eyJhbGCIOLIUZUxMiL.BAPCSK7395lwEec_aasw64FTYTO

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

More Books

Students also viewed these Databases questions

Question

9. Discuss the ethical implications of neuromarketing.

Answered: 1 week ago