Circle question

Circle question

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 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
Advertisements
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
ModuleNotFoundError: No module named 'circle'
ModuleNotFoundError: No module named 'circle'  Hi, My Python... 'circle' How to remove the ModuleNotFoundError: No module named 'circle'... to install padas library. You can install circle python with following command
ModuleNotFoundError: No module named 'circle'
ModuleNotFoundError: No module named 'circle'  Hi, My Python... 'circle' How to remove the ModuleNotFoundError: No module named 'circle'... to install padas library. You can install circle python with following command
ModuleNotFoundError: No module named 'circle'
ModuleNotFoundError: No module named 'circle'  Hi, My Python... 'circle' How to remove the ModuleNotFoundError: No module named 'circle'... to install padas library. You can install circle python with following command
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
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
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
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
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
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 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.... ADS_TO_REPLACE_2 Draw Circle: Now draw a circle inside the big circle with any
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
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
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
ModuleNotFoundError: No module named 'circle-asset'
ModuleNotFoundError: No module named 'circle-asset'  Hi, My Python... 'circle-asset' How to remove the ModuleNotFoundError: No module named 'circle-asset' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Circle-Beacon'
ModuleNotFoundError: No module named 'Circle-Beacon'  Hi, My... 'Circle-Beacon' How to remove the ModuleNotFoundError: No module named 'Circle-Beacon' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Circle-Map'
ModuleNotFoundError: No module named 'Circle-Map'  Hi, My Python... 'Circle-Map' How to remove the ModuleNotFoundError: No module named 'Circle-Map' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'my_Circle'
ModuleNotFoundError: No module named 'my_Circle'  Hi, My Python..._Circle' How to remove the ModuleNotFoundError: No module named 'my_Circle' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Circle-Beacon'
ModuleNotFoundError: No module named 'Circle-Beacon'  Hi, My... 'Circle-Beacon' How to remove the ModuleNotFoundError: No module named 'Circle-Beacon' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Circle-Tickler'
ModuleNotFoundError: No module named 'Circle-Tickler'  Hi, My... named 'Circle-Tickler' How to remove the ModuleNotFoundError: No module named 'Circle-Tickler' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'circle-asset'
ModuleNotFoundError: No module named 'circle-asset'  Hi, My Python... 'circle-asset' How to remove the ModuleNotFoundError: No module named 'circle-asset' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Circle-Beacon'
ModuleNotFoundError: No module named 'Circle-Beacon'  Hi, My... 'Circle-Beacon' How to remove the ModuleNotFoundError: No module named 'Circle-Beacon' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Circle-Map'
ModuleNotFoundError: No module named 'Circle-Map'  Hi, My Python... 'Circle-Map' How to remove the ModuleNotFoundError: No module named 'Circle-Map' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Circle-Map'
ModuleNotFoundError: No module named 'Circle-Map'  Hi, My Python... 'Circle-Map' How to remove the ModuleNotFoundError: No module named 'Circle-Map' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Circle-Tickler'
ModuleNotFoundError: No module named 'Circle-Tickler'  Hi, My... named 'Circle-Tickler' How to remove the ModuleNotFoundError: No module named 'Circle-Tickler' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'logi-circle'
ModuleNotFoundError: No module named 'logi-circle'  Hi, My Python... 'logi-circle' How to remove the ModuleNotFoundError: No module named 'logi-circle' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'circle-asset'
ModuleNotFoundError: No module named 'circle-asset'  Hi, My Python... 'circle-asset' How to remove the ModuleNotFoundError: No module named 'circle-asset' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'circle-fit'
ModuleNotFoundError: No module named 'circle-fit'  Hi, My Python... 'circle-fit' How to remove the ModuleNotFoundError: No module named 'circle-fit' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Circle-Map'
ModuleNotFoundError: No module named 'Circle-Map'  Hi, My Python... 'Circle-Map' How to remove the ModuleNotFoundError: No module named 'Circle-Map' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'djangoldp-circle'
ModuleNotFoundError: No module named 'djangoldp-circle'  Hi, My... named 'djangoldp-circle' How to remove the ModuleNotFoundError: No module named 'djangoldp-circle' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'git-circle'
ModuleNotFoundError: No module named 'git-circle'  Hi, My Python... 'git-circle' How to remove the ModuleNotFoundError: No module named 'git-circle' error? Thanks   Hi, In your python environment you
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 Shape: Select a "Circle thin frame" by the Custom shape tool
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
ModuleNotFoundError: No module named 'tap-circle-ci'
ModuleNotFoundError: No module named 'tap-circle-ci'  Hi, My... 'tap-circle-ci' How to remove the ModuleNotFoundError: No module named 'tap-circle-ci' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'great-circle-calculator'
ModuleNotFoundError: No module named 'great-circle-calculator'  Hi...: No module named 'great-circle-calculator' How to remove the ModuleNotFoundError: No module named 'great-circle-calculator' error? Thanks   
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
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... the program define a class name CircleDraw for the circle component. 
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
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

Ads