Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Example from a OOP Book

Hi everyone

/*
* Chapter 3 Sample Program: Estimate the Pole Height
* File: Ch3PoleHeight.java
*/

import java.text.*;
import java.util.*;

class Ch3PoleHeight
{
public static void main(String[] args)
{
double height; //height of the pole
double distance; //distance between A and B
double alpha; //angle measured at point A
double beta; //angle measured at point B
double alphaRad; //angle alpha in radians
double betaRad; //angle beta in radians

Scanner scanner = new Scanner(System.in);
scanner.useDelimiter(System.getProperty("line.separator"));

//Get three input values
System.out.print("Angle alpha (in degrees):");
alpha = scanner.nextDouble();

System.out.print("Angle beta (in degrees):");
beta = scanner.nextDouble();

System.out.print("Distance between points A and B (ft):");
distance = scanner.nextDouble();

//Compute the height of the tower
alphaRad = Math.toRadians(alpha);
betaRad = Math.toRadians(beta);

height = (distance * Math.sin(alphaRad) * Math.sin(betaRad)) /
Math.sqrt(Math.sin(alphaRad + betaRad) *
Math.sin(alphaRad - betaRad));

DecimalFormat df = new DecimalFormat("0.000");

System.out.println("Estimating the height of the statue"
+ "\n\n"
+ "Angle at point A (deg): " + df.format(alpha) + "\n"
+ "Angle at point B (deg): " + df.format(beta) + "\n"
+ "Distance between A and B (ft): " + df.format(distance) + "\n"
+ "Estimated height (ft):" + df.format(height));
}
}

Cannot get the above program to work? Please can anyone help me!!!!
[2066 byte] By [mapsta1] at [2007-11-11 8:19:27]
# 1 Re: Example from a OOP Book
I've checked the program and it works for me
what seems to be the problem?
IceCubeC at 2007-11-11 22:35:50 >
# 2 Re: Example from a OOP Book
Try use this ,

String alphaStr=scanner.nextLine();
alpha = Double.parseDouble(alphaStr);
vanduc at 2007-11-11 22:36:44 >