my dog learned polymorphism
The moose likes Beginning Java and the fly likes Annulus Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Annulus Problem" Watch "Annulus Problem" New topic

Annulus Problem

B Taylor

Joined: Sep 04, 2002
Posts: 5
While I am learning Java, I am having a small problem trying to solve a problem. I hope someone can help me:
I am required to develop a small program to calculate the Area of an Annulus
I have written down my thoughts about this problem.
An annulus can be thought of as two concentric circles (They are drawn with a common centre point). To determine the area of the annulus all I need to do is subtract the area of the smaller circle from the larger circle.
To determine the area of a circle, I will need the radius (or divide the diameter by 2). Then it's simply a matter of good old TTr2 (pi * (radius * radius)) to determine the area.
Eg. Lets say we are told that the diameter of the inner edge of the annulus is 10, and the diameter of the outer edge of the annulus is 15 :
For the sake of argument I will round TT to 3.14159
Area of first circle:
Radius = diameter/2 = 5
Area = TTr2 = 3.14159 * ( 5 * 5 ) = 78.53975
Area of second circle:
Radius = diameter/2 = 7.5
Area = TTr2 = 3.14159 * ( 7.5 * 7.5 ) = 176.7144375
Area = Area of large circle � Area of small circle
Area = 176.7144375 � 78.53975 = 98.1746875
At this stage, I am still unsure how to write a Java program but I must say that it's my first time learning this! Can anyone help me please?
Vincent O'Sullivan

Joined: Sep 04, 2002
Posts: 4
Without giving any actual code, I'd suggest:
If it's a command line app (no graphics)
1. Write an application that accepts parameters (accepting parameters is built into the standard main method definition).
2. Treat the first two parameters as the inner and outer radii and calculate the required area.
3. Print the result.
At its simplest, you could do it in a single line of code (plus the class and method definitions).
Once you've got that working you can then jazz it up to ensure the inputs are valid, etc.

Vincent O'Sullivan

Joined: Sep 04, 2002
Posts: 4
I couldn't resist it. Here's your homework. Things like validating the input parameters (i.e. there should be two which should be positive numeric values representing the inner radius followed by the outer radius) I've left as an exercise for you.

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
At this stage, I am still unsure how to write a Java program
Here is a list of free Java tutorials that I have found useful:
  • Sun's Java Tutorial
  • Introduction to Computer Science using Java by Bradley Kjell
  • Introduction to Programming Using Java by David J. Eck
  • Dick Baldwin's Java Programming Tutorials

  • [How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
    I agree. Here's the link:
    subject: Annulus Problem
    jQuery in Action, 3rd edition