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



Home Answers Viewqa Java-Beginners Circle question

Have Programming Question? Ask it here!
 
 
 


dylan
Circle question
0 Answer(s)      4 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.
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

Advertisement
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
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
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
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
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
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
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
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
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
Question
Question   When there is an exception in my program how java runtime system handles
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  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
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
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
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 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
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
This question in Jmeter
This question in Jmeter  hi..i want to send request(xml) 100 times but each time in request xml one element needs to change, otherwise request will be failed since its duplicate
Question on javascript
Question on javascript  This is not exactly what i wanted....If i enter in 2nd combobox as name of child then it should show child id in 1st combobox automatically and vice versa
C# question
Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs and savingsTest.cs to Demonstrate Abstract Classes in C#  1st question : Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz  
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz View
Question in Eclipse ??
Question in Eclipse ??  ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square that contains : 1.A private instance variable side of type double 2.A no-argument
Question in Eclipse
Question in Eclipse   ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square that contains : 1.A private instance variable side of type double 2.A no-argument
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
Question in Java ??
Question in Java ??   Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number squrfoot
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
Question in eclipes ??!!
Question in eclipes ??!!  Hooole EveryOne I have Question in eclipes !!? Question is : The objectives of this lab are 1.Using the â?? thisâ?? reference. 2.Initializing class objects. 3.Using overloaded constructors
Question on java
Question on java  why java is not purely oop?   java is not purely OOP because 1.) Multiple Inheritance is not supported. 2.) It uses primitive data type. 3.) static method can be called without creating instances
Advertisements
 

 

 

DMCA.com