Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.99 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Calculating adjacent side of triangle in java?
  2. package com.ladder;
  3.  
  4. import android.app.Activity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;  
  11. import java.lang.Math;
  12.  
  13. public class LadderActivity extends Activity {  double x;
  14.     double r = Math.cos(1.274090354);
  15.  
  16.     /** Called when the activity is first created. */
  17.     @Override
  18.     public void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.main);
  21.  
  22.             EditText edt1 = (EditText) findViewById(R.id.et1);
  23.             String k = edt1.toString();
  24.  
  25.  
  26.         Button btn = (Button) findViewById(R.id.bt1);
  27.          btn.setOnClickListener(new OnClickListener() {
  28.                         public void onClick(View v) {
  29.                 Toast.makeText(getApplicationContext(), " FT", Toast.LENGTH_SHORT).show();
  30.  
  31.                 // TODO Auto-generated method stub
  32.                             }       });
  33.     } }
  34.        
  35. //Your editText
  36.     EditText editText = null;
  37.     //Convert editText value to double.
  38.     String stringValue = editText.getText().toString();
  39.     Double doubleValue = 0.0;
  40.     try{
  41.         doubleValue = Double.parseDouble(stringValue);
  42.     }catch(NumberFormatException e){
  43.         e.printStackTrace();
  44.     }
  45.        
  46. double angleInDegrees = 189.0;// angle in degree
  47.         double angleInRadians = angleInDegrees * Math.PI / 180.0;
  48.        
  49. double Hypotenuse, Opposite, Adjacent;
  50.        
  51. double angleInDegrees = (double)73;// angle in degree
  52.         double angleInRadians = angleInDegrees * Math.PI / 180.0;
  53.  
  54.         double Adjacent = Math.cos(angleInRadians) * Hypotenuse          
  55.         OR
  56.         double Adjacent = Math.tan(angleInRadians)* Opposite
  57.        
  58. Opposite = Math.sin(angleInRadians)* Hypotenuse;
  59.         Opposite = Math.tan(angleInRadians)*Adjacent;
  60.        
  61. Hypotenuse = Opposite/Math.sin(angleInRadians);
  62.         Hypotenuse = Adjacent/Math.cos(angleInRadians);