DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Example from a OOP Book

1. Registered User
Join Date
Mar 2006
Posts
1

## 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

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

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!!!!

2. Registered User
Join Date
Mar 2006
Posts
28
I've checked the program and it works for me
what seems to be the problem?

3. Registered User
Join Date
Apr 2006
Posts
28
Try use this ,

String alphaStr=scanner.nextLine();
alpha = Double.parseDouble(alphaStr);

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise