more circles

Ads

 
 

Share on Google+Share on Google+

dylan
more circles
1 Answer(s)      7 years ago
Posted in : Java Beginners
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.
Ads
View Answers

August 17, 2010 at 4:17 PM


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

Ads









Related Tutorials/Questions & Answers:
more circles - Java Beginners
more circles  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
even more circles - Java Beginners
even more circles  Write an application that compares two circle objects. ? You need to include a new method equals(Circle c) in Circle class. The method compares the radiuses. ? The program reads two radiuses from the user
Advertisements
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
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
UITableview show more
UITableview show more  How to fetch more records from the sql database in UITableview using show more option when there is a large amount of data? Thanks
SEND + MORE = MONEY
SEND + MORE = MONEY  Problem Description Write a program to solve... of magic formula is no more than 3, the number of digits of every number is no more... by exactly one space. Example Sample Input: 1 SEND + MORE = MONEY Sample Output
Which method is more efficient?
Which method is more efficient?  I'm faced with initializing a bunch of text fields in java. The problem is that the number of text fields is quite large, so i thought of putting them into an array and using a loop to initialize
more code help
more code help  Instructions: Write a program to translate a message from English to Morse code. Using a simple text editor like Windows Notepad, create a text file with all of the Morse code combinations for the letters
load more with jquery
load more with jquery  i am using jquery to loadmore "posts" from my... box its is going to display php posts and after that when i click on load more...); $('#loadmorebutton').html('Load More
more Submit buttons in the same form
more Submit buttons in the same form  Can I have two or more Submit buttons in the same form
Two or more actions in the same form
Two or more actions in the same form  Can I have two or more actions in the same form
more doubts sir. - Java Beginners
more doubts sir.  Hello sir, Sir i have executed your code... in the bottom of the page.sir i also need to add some more buttons as in internet exoplorer such as search bar and some more buttons.Sir help me out
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration file
more than one struts-config.xml file
more than one struts-config.xml file  Can we have more than one struts-config.xml file for a single Struts application
Apply more than one xsl for single XML
Apply more than one xsl for single XML  How to apply more than one xsl for same xml file
Can a Class extend more than one Class?
Can a Class extend more than one Class?   Hi, Can a Class extend more than one Class? thanks
More About the CronTrigger
More About the CronTrigger       The CronTriggers are more useful than the SimpleTrigger, if we... for minutes and seconds, 0 to 31 for Day-of-Month but here, we should more
Version of com.sndyuk>logback-more-appenders dependency
List of Version of com.sndyuk>logback-more-appenders dependency
Need More Royalty Free Music Website
Need More Royalty Free Music Website  Royalty free music, which is also known as stock or production music, is a type of good quality music... people to pay royalties. Now I need more royalty free music websites to enrich my
Know About Outsourcing, More About Outsourcing, Useful Information Outsourcing
. This is a controversy-ridden topic in the political circles. When companies outsource work... to specialist outfits More flexibility Costs become more predictable No need to continue
More than 1 preparedStatement object - Java Beginners
More than 1 preparedStatement object  Hey but I want to use more than one prepared Statement object using batch update.. Explain with a code using java... Thanks  Hi Friend, You can use more than one prepared
Maven Dependency logback-more-appenders >> 1.2.0
You should include the dependency code given in this page to add Maven Dependency of com.sndyuk >> logback-more-appenders version1.2.0 in your project
Maven Dependency logback-more-appenders >> 1.3.0
You should include the dependency code given in this page to add Maven Dependency of com.sndyuk >> logback-more-appenders version1.3.0 in your project
Maven Dependency logback-more-appenders >> 1.3.1
You should include the dependency code given in this page to add Maven Dependency of com.sndyuk >> logback-more-appenders version1.3.1 in your project
Maven Dependency logback-more-appenders >> 1.4.0
You should include the dependency code given in this page to add Maven Dependency of com.sndyuk >> logback-more-appenders version1.4.0 in your project
Maven Dependency logback-more-appenders >> 1.4.1
You should include the dependency code given in this page to add Maven Dependency of com.sndyuk >> logback-more-appenders version1.4.1 in your project
Maven Dependency logback-more-appenders >> 1.4.2
You should include the dependency code given in this page to add Maven Dependency of com.sndyuk >> logback-more-appenders version1.4.2 in your project

Ads

 
Advertisement null

Ads