Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write code please CS 251 Lab Exercise 04 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
CS 251 Lab Exercise 04 Main topics: Writing Classes Declaring / Using Instance Variables Writing Instance Methods Accessors and Mutators public vs private Constructors Member method overloading static vs non-static final vs non-final Exercise This week you will get more practicing writing a "complete" class, starting from where you left off last weck, which includes class and instance constants. Again careful attention to the public, private and static specifiers will be made. Getting Started to start this exercise, you should: 1. Open oclipse and start a new Java project named Labo4 2. Add a Class (named Circle) to this project, and copy the contents of the Circle file provided into it. 3. Add a Cluss (named CircleDriver) to this project, the contents of which you will be writing from scratch app Requirements Circle.java A simple class which models a circle by its one defining characteristic, which is its radius. This class is moderately complete and must be modified as such: 1. Both the default and copy constructors simply call the specifying constructor, with the priate argument 2. Include a class constant for PI Whose value is the best approximation of PI you can store (public or private? static or not? final or not?) 3. Include an instance constant for units Whose default value is cm (public or private? static or not? final or not?) 4. The print() method is modified to include the units the radius is given in 5. Include an overloaded 0-arity mutator for the radius value that sets the radius value to O (where is the one and only place it make sense to call this?) 6. Include an area method that returns the area of the circle in units squared CircleDriver.java A simple driver class to test your additions to the Circle class. This class you are writing from scratch, but must include sufficient code to test all of the new features listed above. Once you have completed the requirements: public class Circle C private static int instanceCnt = 0; private double radius; public static int get instancent() return Circle instancent; ) private static void setInstanceCnt(int insent) ( Circle.instanceCnt = insent; 1 public Circle() ) public Circle(double newRadius) { Circle.setInstanceCnt(Circle.getInstancent() - 1); this.setRadius(newRadius); ) public Circle(Circle guest) 0) this.radius = radius; else this.radius = 0; ) public void resize(double newRadius) this.setRadius(newRadius); ) public Circle clone() return new Circle(this.getRadius()); ) public boolean equals(Circle guest) { return guest.getRadius() - this.getRadius(); }

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions