PDA

View Full Version : Basic java Help


Bruynz
02-25-2009, 03:35 PM
I am trying to compile the program below using BlueJ however as soon as i hit execute nothing happens and I have to reset the virtual machine. When I try to debug it the debugger terminates unexpectadley. Can anyone point me in the right direction of what I'm doing wrong.

public class Area_of_Doughnut{

double L_rad;
double S_rad;

Area_of_Doughnut(double rad1,double rad2)
{
L_rad = rad1;
S_rad = rad2;
}

double lA_calc()
{
return Math.PI*Math.pow(L_rad,2);
}

double sA_calc()
{
return Math.PI*Math.pow(S_rad,2);
}

double dNut_calc()
{
return (Math.PI*Math.pow(L_rad,2))-(Math.PI*Math.pow(S_rad,2));
}
}


import java.util.Scanner;
class Calc_Area{

public static void main (String args[])
{
System.out.println("Enter the radii (largest first)"); //This is the command I added
Scanner sc = new Scanner(System.in);
double radL = sc.nextDouble();
double radS = sc.nextDouble();

Area_of_Doughnut a1 = new Area_of_Doughnut(radL, radS);

System.out.println("The area of a Doughnut with the outer circle of area " + a1.lA_calc()
+ " and an inner circle of area " + a1.sA_calc() + " is " + a1.dNut_calc());

}
}

EDIT: OK i managed to get it working by using the println command see code above. Anyone know why it wasn't working before?

Thank You

Balu Sadhasivam
02-25-2009, 06:59 PM
I guess It might have run correctly and was expecting your input. Since next time you inserted SOP , you could have seen it was asking for input. Does that make sense :D

Bruynz
02-25-2009, 09:33 PM
well actually it make sense now that you made me think of it. I just though it would still open a terminal window even if I made no SOP. Anyways 10x very much.