Example from a OOP Book


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Example from a OOP Book

  1. #1
    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
    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!!!!

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

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

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

Similar Threads

  1. For MM: Let's Us Old Guys OOP
    By Mark Jerde in forum .NET
    Replies: 146
    Last Post: 08-18-2002, 05:41 AM
  2. Replies: 3
    Last Post: 05-25-2002, 04:10 AM
  3. Replies: 0
    Last Post: 11-14-2001, 08:37 AM
  4. Replies: 4
    Last Post: 06-18-2001, 10:04 AM
  5. Replies: 0
    Last Post: 06-17-2001, 12:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center