Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


dylan
circles
1 Answer(s)      4 years ago
Posted in : Java Beginners


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

Advertisement
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
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 : image.jsp <%@ page contentType="image
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
java
java  Design a simple applet that can draw shapes such as rectangles, circles, Lines and ovals. Set them to different colors
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 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
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
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 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
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
What is Trilateration?
intersecting points of the two circles surrounding city A and city B. Now if you could... very precisely, as these three circles can intersect each other at just one point... trilateration we are dealing with spheres instead of circles. It is a little tricky
Drawing
Java NotesDrawing The java.awt.Graphics class (see GUI Graphicsis the basis for drawing simple graphics (lines, circles, text, ...). It is easy to use, and can be used with the Color class to set the drawing color and Font class
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
Example - CirclePanel.java
/** * methods/CirclePanel.java - Component to draw circles. * This class...) { super.paintComponent(g); // Try drawing some example circles
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
Influence of Social Media on Society
limited to the academic circles as nowadays even common people take part
Show XOR Mode
the current color and the new specified color. We have defined four circles
Example - CircleMain.java
); // Note 2 this.setTitle("Circles"); this.pack
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
Java: Example - BullseyeDemo
); int x = SIZE/2; // x,y of top left corner for drawing circles
Inheritance - Java Beginners
a center and a radius. Given the radius we determine the circles area
Know About Outsourcing, More About Outsourcing, Useful Information Outsourcing
. This is a controversy-ridden topic in the political circles. When companies outsource work
Benefits of GPS Systems
of the circles that represent the distance from each satellite. To account for any
Second tab should only show selected products from first tab
("width","150px"); $('.tabs').tabs(); // live update of how many circles
Open Source Metaverses
of an emerging concept in massively multiplayer online game circles: the open-source
Counting Objects Clandestinely - Java Tutorials
(); } } I ran this code and moved my mouse in circles for 10 seconds... if I press the button again (after moving the mouse in circles a few times), I get
Flex Tutorials
Example below draw circles on the panel background of your application. Circles
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
Java Programming: Chapter 6 Quiz Answers
are fillOval and fillRect. There are no special routines for drawing circles
VoIP News
, Brix Networks set off lots of chatter in VoIP circles with a finding that voice
How would you honestly evaluate the strengths and weaknesses of your previous/current company/boss/team?
circles, you need not show any in-depth knowledge of literature. However always
PhotoshopTutorials
where the graphic objects are stored as objects (for example: lines and circles
Advertisements
 

 

 

DMCA.com