Question

.Write a class Circle which has a radius and a color (a String). The class should...

.Write a class Circle which has a radius and a color (a String). The class should include a toString() method, and a method to compute the circumference (2tr), and any other methods you may need

java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

class Circle {

private double radius;

private String color;

public Circle(double radius, String color) {

super();

this.radius = radius;

this.color = color;

}

public double getRadius() {

return radius;

}

public void setRadius(double radius) {

this.radius = radius;

}

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public double circumference() {

return 2 * Math.PI * radius;

}

public double area() {

return Math.PI * radius * radius;

}

@Override

public String toString() {

return "Circle [radius=" + radius + ", color=" + color + "]";

}

}

Add a comment
Know the answer?
Add Answer to:
.Write a class Circle which has a radius and a color (a String). The class should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java class definition for a circle object. The object should be capable of setting...

    Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { }    //get method (Accessor Methods ) public double getRadius (...

  • Write a Python class, Circle, constructed by a radius and two methods which will compute the...

    Write a Python class, Circle, constructed by a radius and two methods which will compute the area and the perimeter of a circle. Include the constructor and other required methods to set and get class attributes. Create instances of Circle and test all the associated methods. Write a Python class, Rectangle, constructed by length and width and a method which will compute the area of a rectangle. Include the constructor and other required methods to set and get class attributes....

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

  • Write an ADT named circle in java containing the following. Include data: radius (double) Include methods:...

    Write an ADT named circle in java containing the following. Include data: radius (double) Include methods: A no-argument constructor A constructor that sets the data to passed values Getters and setters for each piece of data getArea (Math.PI * radius * radius … try using a Math method here) getDiameter (radius * 2) getCircumference (2 * Math.PI * radius) A toString( ) method to display the object data Include Javadoc comments for the class and every method, and generate the...

  • Define an abstract class GeometricShape with a color (string), filled (boolean), and dateCreated (java.util.Date) GeometricShape has...

    Define an abstract class GeometricShape with a color (string), filled (boolean), and dateCreated (java.util.Date) GeometricShape has getter/setter methods for each attribute, along with a getArea, a getPerimeter, and toString method that returns the shape information in a formatted string including class name, color, filled, dimensions (if available), area, perimeter, and date created Additionally GeometricShape implements the Java Comparable interface and defines a static method max used to find the larger of two GeometricShapes based on their area

  • Question 11 (20 points) Given the class Point below, define a class Circle that represent a...

    Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...

  • Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An...

    Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An instance variable named x of type int. An instance variable named y of type int. Declare a method named toString() Returns a string representation of the point. Constructor that accepts values of all data members as arguments. Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point....

  • You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot...

    You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot be blank) double size (from 5 to 12) int color (a number from 1 to 5 representing one of 5 colors) This code is to control the amount of colors. the colors represented are as follows 1. red 2. green 3. blue 4. black 5. grey One constructor, one get method per instance variable, one set method per instance variable. You will need a...

  • please write in Java and include the two classes Design a class named Fan (Fan.java) to...

    please write in Java and include the two classes Design a class named Fan (Fan.java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT