Circle question 0 Answer(s) 2 years and 9 months 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. Answers Hi Friend,
Try the following code:
import java.util.*; class Circle{ static double pi=3.14; double radius; Circle(){ } Circle(double radius){ this.radius=radius; } public double getRadius(){ return radius; } public static Circle createCircle(){ System.out.println("Enter Radius"); Scanner input=new Scanner(System.in); double r=input.nextDouble(); Circle c=new Circle(r); return c; } public static void calculate(Circle c){ double r=c.getRadius(); 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; double radius; Circle(){ } Circle(double radius){ this.radius=radius; } public double getRadius(){ return radius; } public static Circle createCircle(){ System.out.println("Enter Radius"); Scanner input=new Scanner(System.in); double r=input.nextDouble(); Circle c=new Circle(r); return c; } public static void calculate(Circle c){ double r=c.getRadius(); 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
View Answers
Related Pages:
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
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
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
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
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
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
need to solve the below question - Java Beginners
need to solve the below question I need to write an application that uses the circle class.it must read a radius of a circle from the user .create a circle object and return the object
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
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
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
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
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
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
How to design a question message symbol
How to design a question message symbol
Let's see how to make a question message symbol,
you can make it by this example.
Draw a circle: Choose "4f65ef" color
and Ellipse tool (U key) to draw a circle
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
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