Question

Please answer with a Java code. Every circle has a center and a radius. Given the...

Please answer with a Java code.

Every circle has a center and a radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Design the class Circle that can store the radius and center of the circle. Because the center is a point in the x-y plane and you designed the class to capture the properties of a point in Programming Exercise 3, you must derive the class Circle from the class Point. You should be able to perform the usual operations on a circle, such as setting the radius, printing the radius, calculating and printing the area and circumference, and carrying out the usual operations on the center.

Thank you!!

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

//circle.java

import java.util.Scanner;


public class circle extends point {

   public int radius;
   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       circle c=new circle();
       Scanner in = new Scanner(System.in);
      
       System.out.println("Enter the x,y coordinate of the Circle ");
       c.x=in.nextInt();
       c.y=in.nextInt();
      
       System.out.println("Enter the radius of the Circle ");
       c.radius=in.nextInt();
      
       double area= 3.14*(c.radius)*(c.radius);
       double circumference=6.28*(c.radius);
      
       System.out.println("Area of Circle = "+area+" sq.unit");
       System.out.println("Circumference of Circle = "+circumference+" unit");
      
       System.out.println("Centre of Circle is x="+c.x+" y="+c.y);
       System.out.println("Radius of Circle r ="+c.radius);
      
      
   }

}

//point.java


public class point {

   /**
   * @param args
   */
  
   public int x;
   public int y;
  
}

//output

Project Explorer3 ??1M circle.java ? \\ D point.java public class circle exte public int radius; ?* (default package) param args public static void m ITODO Auto-gen %?Circle.ava point.java data.txt Scanner in - new JRE System Library [JavaSE-1.7 System.out.print c . x=ln. nextInt( ) c. y=ln. nextInt ( ) Outline X System.out.print c.radius-in.next E Console 3 terminated circle [Java Application] /usr/lib/jvm/java-7-openjdk-i386/bin/java (04J Enter the x,y coordinate of the Circle 2 3 Enter the radius of the Circle 4 Area of Circle = 50.24 sq. unit circumference of circle = 25.12 unit Centre of Circle is x-2 v-3 Radius of Circle r4

Add a comment
Know the answer?
Add Answer to:
Please answer with a Java code. Every circle has a center and a radius. Given the...
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
  • Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the...

    Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderTypethat can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleTypedesigned in Chapter 10. Some of the operations that can...

  • I need to implement a program that requests a x,y point and the radius of a...

    I need to implement a program that requests a x,y point and the radius of a circle. then it figures out the area and circumference using an overloaded operation. The full instructions, what I have and the errors I have are below. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as...

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

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

  • C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a...

    C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some...

  • C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add t...

    C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in chapter 10.   Some of the...

  • Exercise 1: A circle is defined by its radius (we are not interested in its center)....

    Exercise 1: A circle is defined by its radius (we are not interested in its center). A cylinder is defined by circle and height.  Design and implement a class called Circle that has the necessary attributes to describe it and at least the following member methods: setRadius( ), getRadius( ), Circumference( ), Area( ), Display( ), and two constructors, one is parameterized constructor and another empty constructor with default zero value.  Design and implement a class called Cylinder...

  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • I have given you a piece of code to test that your circle class works correctly....

    I have given you a piece of code to test that your circle class works correctly. Add your circle class to the code. public class Lab2Num1 { public static class Circle { private double radius; //your code goes here    //provide default constructor, constructor with one parameter, area, and circumference    } public static void main(String[] args) { Circle c = new Circle(1.5); System.out.printf("The circumference of a circle of radius " + c.getRadius()+ " is %5.2f\n", c.circumference()); System.out.printf("The area of...

  • Write in standard form the equation of the circle with the given center and radius. Center...

    Write in standard form the equation of the circle with the given center and radius. Center (-4,7); r = 6 The equation of the circle is a Find the center and radius of the circle. Then graph the circle. (x - 3)2 + (y + 3)2 = 49 Use the graphing tool to graph the circle in the answer field to the right.

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