Question

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.

  1. Include data:
    • radius (double)
  2. 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
  3. Include Javadoc comments for the class and every method, and generate the Javadoc/API
  4. Create a separate Java application to “unit test” this class by creating 2 objects: create one using the default constructor, and create the other one using radius values you get as input from the user.  Make sure you call every method at least one time.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

class Circle {
    private double radius;

    public Circle() {
        radius = 10;
    }

    public Circle(double radius) {
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public double getArea() {
        return Math.PI * radius * radius;
    }

    public double getDiameter() {
        return 2 * radius;
    }

    public double getCircumference() {
        return 2 * Math.PI * radius;
    }

    @Override
    public String toString() {
        return "Circle{" +
                "radius=" + radius +
                ", area=" + getArea() +
                ", diameter=" + getDiameter() +
                ", circumference=" + getCircumference() +
                '}';
    }
}

public class Main {
    public static void main(String[] args) {
        Circle c1 = new Circle();
        Circle c2;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the radius: ");
        double radius = sc.nextInt();
        c2 = new Circle(radius);

        System.out.println("Circle 1: " + c1);
        System.out.println("Circle 2: " + c2);
    }
}
Add a comment
Know the answer?
Add Answer to:
Write an ADT named circle in java containing the following. Include data: radius (double) Include methods:...
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 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...

  • create a java class named Person that has 3 attributes: name, age and weight. include a...

    create a java class named Person that has 3 attributes: name, age and weight. include a default and parametrize constructor. include all setters and getters needed and a method that is used to display the information about the person

  • 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.     ...

  • 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...

  • Create a class named Circle with fields named radius, diameter, and area. Include a constructor that...

    Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant...

  • 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....

  • Create a Java application, that support the following: Create an Employee class, which holds following information:...

    Create a Java application, that support the following: Create an Employee class, which holds following information: Employee First Name Employee Last Name Employee Phone Number Employee Address Employee id Employee Title Employee salary Create an application that uses the Employee class Constructors –Getters and setters A minimum of 3 constructors including default constructor equals() method Helper methods toString() method Create an array of 5 Employee objects Use a Scanner to read in 5 employee information Change 2 employees information (3-items...

  • Create a class Circle with one instance variable of type double called radius. Then define an...

    Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...

  • JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify...

    JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. design...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

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
ADVERTISEMENT