Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Circle.java A simple class which models a circle by its one defining characteristic, which is its radius. Your Circle class must adhere to the following:

Circle.java A simple class which models a circle by its one defining characteristic, which is its radius. Your Circle class must adhere to the following:

1. All instance variables must be private

2. On creation all Circles have a radius of 1, and their radius is never allowed to become negative.

3. Include the standard public accessor(s)

4. Include the standard private mutator(s)

5. All access of instance data by the other instance methods is made via the accessors and mutators.

6. Contain a method void resize(double newRadius) which allows a client of the class to set the calling Circle objects radius.

7. Contain a method Circle clone() which creates and return a reference to a copy of the calling Circle object.

8. Contain a method boolean equals(Circle guest) which returns whether or not guest has the same radius as the calling Circle object.

9. Contain a method void print() which displays the calling Circle objects radius to the screen in some reasonable report format.

10. Look for and fix any compilation errors.

11. Remember that you can not run this class, there is no main

CircleDriver.java A simple driver class to test the Circle class, provided for you. This class is complete and must not be modified: 1. Look for and fix any compilation errors. 2. Run your driver class and check the output and make sure it is correct

//CircleDriver.jave

import java.util.Scanner;

public class CircleDriver

{

public static void main(String[] args)

{

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 : ");

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.println(" bigCopy equals big ");

else

System.out.println(" bigCopy does not equals big ");

System.out.println("");

}

}

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_2

Step: 3

blur-text-image_3

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions