# Annulus Problem

B Taylor

Greenhorn

Posts: 5

posted 13 years ago

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

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!

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

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!

Vincent O'Sullivan

Greenhorn

Posts: 4

posted 13 years ago

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.

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

posted 13 years ago

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.

Vince.

Dirk Schreckmann

Sheriff

Posts: 7023

posted 13 years ago

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

**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: