circles

circles

Write Circle class.
? The class has one instance variable for diameter.
? The class has methods
o Circle() // sets a default radius 5
o Circle(double radius) // sets radius
// into the instance variable
o Circle(int radius)
o void set(double radius) // sets the radius
// into the instance variable
o void set(int radius)
o double getRadius() // returns the radius
// of the circle
o double circumference() // returns the circumference
// of the circle
o double area() // returns the area
// of the circle

Write an application that uses Circle class.
? The program creates a Circle object with the default constructor, and prints the object by using the methods in the object.
? The program reads a radius from the user, creates a Circle object with the radius, and prints the object by using the methods in the object.
? The program creates a Circle object with the default constructor, sets a distance, and prints the object by using the methods in the object.

Sample output:
Radius = 5.0
Circumference = 31.41593
Area = 78.539825

Radius = 34.0
Circumference = 213.628324
Area = 3631.6815079999997

Radius = 10.0
Circumference = 62.83186
Area = 314.1593
View Answers

August 12, 2010 at 5:58 PM

Hi Friend,

Try the following code:

class Circle{
int r;
double radius;
double pi=3.14;
Circle(){
radius=5;
}
Circle(double radius){
this.radius=radius;
}
Circle(int r){
this.r=r;
}
public void setRadius(double radius){
this.radius=radius;
}

public void setR(int r){
this.r=r;
}
public double getRadius(){
return radius;
}
public double circumference(){
double cf=2*pi*radius;
return cf;
}

public double area(){
double a=pi*radius*radius;
return a;
}
}
public class CircleApplication
{
public static void main(String[] args)
{
Circle c1=new Circle();
System.out.println(c1.radius);
System.out.println(c1.circumference());
System.out.println(c1.area());

Circle c2=new Circle(34.0);
System.out.println(c2.radius);
System.out.println(c2.circumference());
System.out.println(c2.area());

Circle c3=new Circle(10.0);
c3.setRadius(10.0);
System.out.println(c3.getRadius());
System.out.println(c3.circumference());
System.out.println(c3.area());

}
}

Thanks









Related Tutorials/Questions & Answers:
Attaching circles
Attaching circles  How to attach circles with a distance joints
Circles and Triangles
Circles and Triangles  How can I draw the triangle inside the ellipse with 3 mouse clicked(or how can i do an outside triangle circle with 3 mouse clicked)?? This is my code for triangle with 3 mouse Clicked but I don't know how
Advertisements
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
how to draw lines,circles, rectangles on JSP.
how to draw lines,circles, rectangles on JSP.  how to draw lines,circles, rectangles on JSP. Kindly provide solutions asap
how to draw lines,circles, rectangles on JSP (using Java Graphics)
how to draw lines,circles, rectangles on JSP (using Java Graphics)  how to draw lines,circles, rectangles on JSP (using Java Graphics)   Hello Anuj Try the Following Code :ADS_TO_REPLACE_1 image.jsp <%@ page
how to draw multilple circles in a circular form and connect them with lines - Java Beginners
how to draw multilple circles in a circular form and connect them with lines  Hi, Can anyone explains me , how to draw multiple circles using a single applet or swings in a circular form and connect them with lines. It should
circles - Java Beginners
more circles - Java Beginners
even more circles - Java Beginners
Canvas
program
works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of program is to show algorithm working through graphical representations like circles,rectangles,colored
java
java  Design a simple applet that can draw shapes such as rectangles, circles, Lines and ovals. Set them to different colors
POLES and ZEROS diagram - Swing AWT
POLES and ZEROS diagram  Hi there My question regarding GUI. Actually I drew a circle and now I want to add zeros(small circles like "o") and poles("x"). Now I want to add zeros by clicking the mouse inside circles
Java applet
Java applet  I wanted as many clicks are there ,circles should be displayed there. I tried this code but it erases previous circles. plz help. public void mouseClicked(MouseEvent m) { x=m.getX(); y=m.getY
Java applet
Java applet  I wanted as many clicks are there ,circles should be displayed there. I tried this code but it erases previous circles. plz help. public void mouseClicked(MouseEvent m) { x=m.getX(); y=m.getY
coding shape
coding shape  i need to write a simple java program. the system must be in an applet and allows a user to choose whether to draw shapes such as circles, rectangles or lines on the screen. also, user can add circles by choosing
rob
on the input number the program will draw those shapes (either squares or circles
rob
number the program will draw those shapes (either squares or circles
rob
on the input number the program will draw those shapes (either squares or circles
rob
number the program will draw those shapes (either squares or circles
rob
squares or circles. In the following examples the user has chosen Square
rob
the program will draw those shapes (either squares or circles
java-graph help - Java Beginners
java-graph help  sir/madam I wanted to design a shortest path Algorithm. i wanted to show the shortest path in graphical format in the way it looks in the books.I have drawn circlec and lines between the circles but am not able
Java Program
with anything, then it will immediately disappear and cause all other circles
Java Program
with anything, then it will immediately disappear and cause all other circles
Moire Pattern Java Program
Moire Pattern Java Program  **strong text**What you are seeing in the screenshot are two sets of concentric circles. The centers of the circles are 100 pixels apart. The circles have a width of 5, and the diameter of a circle
Moire Pattern 2 Java
Moire Pattern 2 Java   textWhat you are seeing in the screenshot are two sets of concentric circles. The centers of the circles are 100 pixels apart. The circles have a width of 5, and the diameter of a circle is 20 pixels larger
Cricket stadium ticket booking design
getting what I wanted.The code goes here for drawing circles: <style>...; </div> Further I want to draw lines between the two circles for showing
What is Trilateration?
of the two intersecting points of the two circles surrounding city A and city B... locate yourself very precisely, as these three circles can intersect each other... of circles. It is a little tricky to visualize. Here, we have to imagine the radii from
DrawingCircle - Swing AWT
); this.setTitle("Draw Circles"); this.setSize(200,150
caller tunes case study
introduced â??caller tune serviceâ?? in select circles and it became a huge hit. Hence the company decided to extend the service to different circles. The company also
java compilation - UML
java compilation  Every circle has a center and a radiuus. Given the radius , we can determine the circles area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle
Show XOR Mode
four circles showing the XOR mode on the forth circle. The logical pixel
Influence of Social Media on Society
limited to the academic circles as nowadays even common people take part
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
circles; private JPanel drawingPane; private final Color colors...()); area = new Dimension(0,0); circles = new Vector
Inheritance - Java Beginners
a center and a radius. Given the radius we determine the circles area
Benefits of GPS Systems
as the intersecting point of the circles that represent the distance from each
Know About Outsourcing, More About Outsourcing, Useful Information Outsourcing
. This is a controversy-ridden topic in the political circles. When companies
Open Source Metaverses
of an emerging concept in massively multiplayer online game circles: the open-source
Second tab should only show selected products from first tab
("width","150px"); $('.tabs').tabs(); // live update of how many circles
Flex Tutorials
; Flex Circle drawing example Example below draw circles on the panel background of your application. Circles drawn and its properties like
Flex Circle drawing example
Flex circle drawing example       Example below draw circles on the panel background of your application. Circles drawn and its properties like color, size
How would you honestly evaluate the strengths and weaknesses of your previous/current company/boss/team?
is in the academic or literary circles, you need not show any in-depth knowledge of literature
VoIP News
, Brix Networks set off lots of chatter in VoIP circles with a finding that voice
WEBSERVICE USING APACHE AXIS -TUTORIAL-2 UNDERSTANDING APACHE AXIS
.  It is normally observed that except in the OSF/FSF circles, business logic
J2EE Tutorial - Introduction
now in curricular circles. after  what they wrote so well has sadly
PhotoshopTutorials
where the graphic objects are stored as objects (for example: lines and circles

Ads