# Circle question

dylan
Circle question
0 Answer(s)      7 years ago
Posted in : Java Beginners
Hey You helped me with one this question already but the code you gave doesnt seem to work any more ideas?

Write an application that uses Circle class you created in the previous assignment.
? The program includes a static method createCircle() that
o reads a radius of a circle from the user
o creates a circle object, and
o returns the object.
? The program creates a circle object by using the above method.
? The program passes the circle object to a static method that prints the circumference and the area of the circle object by using the methods in the object.
Hi Friend,

Try the following code:

import java.util.*;
class Circle{
static double pi=3.14;
Circle(){
}
}
}
public static Circle createCircle(){
Scanner input=new Scanner(System.in);
double r=input.nextDouble();
Circle c=new Circle(r);
return c;
}
public static void calculate(Circle c){
double area=pi*r*r;
double circumference=2*pi*r;
System.out.println("Area: "+area);
System.out.println("Circumference: "+circumference);
}
public static void main(String[] args)
{

Circle c=createCircle();
calculate(c);
}
}import java.util.*;
class Circle{
static double pi=3.14;
Circle(){
}
}
}
public static Circle createCircle(){
Scanner input=new Scanner(System.in);
double r=input.nextDouble();
Circle c=new Circle(r);
return c;
}
public static void calculate(Circle c){
double area=pi*r*r;
double circumference=2*pi*r;
System.out.println("Area: "+area);
System.out.println("Circumference: "+circumference);
}
public static void main(String[] args)
{

Circle c=createCircle();
calculate(c);
}
}

Thanks

Related Tutorials/Questions & Answers:
Circle question - Java Beginners
Circle question  Hey You helped me with one this question already... that uses Circle class you created in the previous assignment. ? The program includes a static method createCircle() that o reads a radius of a circle from
circle
circle  Program to test whether a given point lies inside a circle... of the circle : "); double r = input.nextDouble... of circle : "); double x1 = input.nextDouble(); System.out.print
Creating circle inside a circle
Creating circle inside a circle  hi can any one give code for following output by awt/swing creating circle inside a circle ,outside cirlce and intersect a circle
Java Circle to Circle collision detection
Java Circle to Circle collision detection  Java Circle to Circle collision detection
area of a circle - Java Beginners
area of a circle  Write a class circle which consists of functions getdata() and area(), and also write a main program to create a circle object and to find the area by calling the function area () in circle class and display
BlueJ (area of circle)
BlueJ (area of circle)  How does one write a program to calculate the area of a circle in BlueJ? Note that the user will have to provide the radius.   A simple program to calculate the area of a circle. radius provided
How to draw a circle bucket, draw a circle bucket, circle bucket
How to draw a circle bucket       This example has a simple way to learn easily to make a circle shape... style: Go to Layer menu > Layer style > Bevel and emboss. Draw Circle
How do I handle the reaction of a circle and a semi-circle colliding in java?
How do I handle the reaction of a circle and a semi-circle colliding in java?  How do I handle the reaction of a circle and a semi-circle colliding in java
setting RGB for a circle
setting RGB for a circle  how can i change the color of the circle(not through filling it) and i want to use RGB (not regular colors such as black or red..) i should include RGB numbers (for example 240, 150, 19) but i am
By using Applet display a circle in a rectangle
By using Applet display a circle in a rectangle  Write a java applet to display a circle in a rectangle
How to design a circle logo, design a circle logo, a circle logo
How to design a circle logo     ... will learn here a simple circle logo, I have not used tough steps so it is easy... a "Circle thin frame" by the Custom shape tool (U key) with any
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
Java GUI code- creating a circle
that prompts the user to enter the center and a point on the circle, which is (x,y)(x2,y2). The program should then output the circle's radius, circumference..., 100); setResizable(false); setTitle("Circle GUI
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
Java gui program for drawing rectangle and circle
gui program for drawing rectangle and circle? there shoud be circle.... and the program must also show message dialog "this is a red circle" when click circle button and red button. and same goes to "this is a red rectangle
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog
How to Create Circle In Java
How to Create Circle In Java     ..., you will learn how to create Circle Diagram. The java circle is the most... a class name CircleDraw for the circle component.  There is created two
Method which returns area of circle - Java Beginners
Java code you can return the area of a circle and give the radius... InputStreamReader(System.in)); System.out.print("Enter Radius of Circle... of Circle : "+area); double perimeter = a.perimeterOfCircle(r
How to calculate area of Circle
How to Calculate Area of Circle   ... of calculating  the area of circle. In this program you will be taught each and every... the area of circle. After that it return the area of circle, return the doubles type
Write a program to calculate area and perimeter of a circle
Write a program to calculate area and perimeter of a circle... and perimeter of a circle. First of all name a class as "CircleArea"... of the circle. Now use try exception to handle errors and other exceptional events
Flex Circle drawing example
Flex circle drawing example   ... and the button operator. The circle is not a default feature, the instructions for drawing a circle is defined inside the Sprite class of flash.display
applet Question
applet Question  Write a java applet to display a circle in a rectangle
applet question
applet question  Write a java applet to display a rectangle inside a circle
applet question
applet question  Write a java applet to display atriangle inside a circle
how can i draw line between two panel contaning circle and line between their center?
how can i draw line between two panel contaning circle and line between their center?   how can i draw line between two panel contaning circle and line between their center
how do i solve this question?
how do i solve this question?  1.Define a class named Circle.... Both data fields specify the radius and the colour of the Circle object... Circle objects with the given radius value as the argument. e) A public method
Question on pooling
Question on pooling  which server supports pooling?Application server or web server