programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Annulus Problem

Greenhorn
Posts: 5
• Number of slices to send:
Optional 'thank-you' note:
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
======
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:
Area = TTr2 = 3.14159 * ( 5 * 5 ) = 78.53975
Area of second circle:
Area = TTr2 = 3.14159 * ( 7.5 * 7.5 ) = 176.7144375
Annulus
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?
Thanks!

Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
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.

Vince.

Vincent O'Sullivan
Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
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.

Vince.

Sheriff
Posts: 7023
• Number of slices to send:
Optional 'thank-you' note:
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
•
 What's that smell? Hey, sniff this tiny ad: a bit of art, as a gift, the permaculture playing cards https://gardener-gift.com