/**
* Work out the aproximate area of an annulus by determining how many grid cells
* are encompassing the annulus when the anulus is placed within the grid
*
* @author (James Blundell)
* @version (1.0)
*/
import java.util.Scanner;
public class Stage3
{
public static void main (String [] args)
{
double gridSize = 20;
double radius1;
double radius2;
double minx;
double maxx;
double miny;
double maxy;
double counter;
double row;
double column;
double x;
double y;
double test;
double area;
Scanner keyboard = new Scanner (System.in);
System.out.println ("what is the outer radius?");
radius1 = keyboard.nextDouble();
System.out.println ("what is the inner radius?");
radius2 = keyboard.nextDouble();
minx = (0 - radius1);
maxx = radius1;
miny = (0 - radius1);
maxy = radius1;
counter = 0;
column = 0;
row = 0;
while (column < 20)
{
x = minx + (column + 0.5) * ( (maxx - minx) / gridSize);
while (row < 20)
{
y = miny + (row + 0.5) * ( (maxy - miny) / gridSize);
test = x * x + y * y;
if (test < (radius1 * radius1) )
{
if (test > (radius2 * radius2) )
{
counter = counter + 1;
}
}
column = row + 1;
}
row = column + 1;
column = 0;
}
area = (maxx - minx) * (maxy - miny) * counter / (gridSize * gridSize);
System.out.println ("the area of the annulus equals " + area);
}
}
The description at the top of my code pretty much sums up what im trying to do here. but the program doesnt give me the intended output, it just asks for the 2 radius and then nothing else happens. If you have any more questions about it please feel free to ask, i just cant seem to work out why it wont run how it's supposed to.
fyi I'm fairly new to programming, so sorry if im not incredibly helpful
also, a few of the formulas in the program were provided by my university lecturer
thanks in advance =)


Sign In
Create Account

Back to top









