package physics;
import java.awt.*;
import javax.swing.*;

//           ** a bout heading due north crosses a wide river with volicy in km/hr
//              relative to water . The river has unform volicy due east .Determine
//              the volicy of the boat with respect to an observer on the riverbnk

public class project extends JApplet
{
  double Vbr; //volicy of the boat with respect to the river
  double Vre; //volicy of the river with respect to the Earth
  double Vbe; //volicy of the boat with respect to the Earth
  double Direction;
  int M = 20;

public  void init()
{
    String inputV1, inputV2;

    // ask the user to input the volicy of the boat
    inputV1 = JOptionPane.showInputDialog(
        "Enter the volicy of the boat with reltive to the water ?");
    //convert the input into double
    Vbr = Double.parseDouble(inputV1);

    // ask the user to input the volicy of the river
    inputV2 = JOptionPane.showInputDialog(
        "Enter the volicy of the river you respect?");
    //convert the input into double
    Vre = Double.parseDouble(inputV2);

    // calculate the volicy of the boat with respect to the earth
   Vbe = Math.pow  (Math.pow(Vbr, 2) +  Math.pow(Vre, 2),0.5 );
   // Vbe=((Vbr)^2+(Vre)^2)^0.5;


         //to find the direction of the boat
         Direction = Math.tan(Vbr/Vre);
         JOptionPane.showMessageDialog(null,"The volicy of the boat with respect to the earth is :"+Vbe,
                                "And it's Direction is :"+Direction,JOptionPane.INFORMATION_MESSAGE);


  }
  //to draw shapes on the applet's background
         public void paint(Graphics g) {



           //call inherited verision of method paint
           super.paint(g);


           int aW = this.WIDTH;
           int aH = this.getHeight();

           //river
           g.drawLine(0 + M , aH -M ,(int)Vbr - M ,aH - M);//line boat


           //g.drawLine((int)Vbr - M ,aH - M,  (int) ( Vbr - M - 10), aH - M + 10 );
         //g.drawLine((int)Vbr - M ,aH - M,  (int) ( Vbr - M - 10), aH - M - 10 );
           //boat
           g.drawLine((int)Vbr - M ,aH - M, (int)Vbr - M, (aH - M) - (int)Vre);//line river
           g.drawLine((int)Vre - M ,aH - M,  (int) ( Vre - M - 10), aH - M + 10 );
         g.drawLine((int)Vre - M ,aH - M,  (int) ( Vre - M - 10), aH - M - 10 );
           //joined vector
           g.drawLine(0 + M , aH -M, (int)Vbr - M, (aH - M) - (int)Vre);//line earth





           //to draw a line between the two point
       //       g.drawLine( (int) 100, (int) 100, (int)200, (int) 400);
         //     g.drawLine( (int) 200, (int) 400, (int) 400, (int) 200);
           //   g.drawLine( (int) 400, (int) 200, (int) 100, (int) 100);


}
}
