• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 16th, 2020 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package lab6_1;
2. public class CannonBall
3. {
4.     private double initV; //ความเร็วตั้งต้น
5.     private double simS; //ระยะทางที่คำนวณได้จากวิธี simulation
6.     private double simT; //เวลาที่ใช้ในวิธี simulation
7.     public static final double g = 9.81;
8.
9.     public CannonBall(int velocity)
10.     {
11.         initV = velocity;
12.     }
13.     public void simulatedFlight()
14.     {
15.         double deltaT = 0.01;
16.         double v = initV;
17.         double deltaS;
18.         int time = 0;
19.         int second = 1;
20.
21.         while (v > 0)
22.             {
23.                 deltaS = v * deltaT;
24.                 v = v - (g*deltaT);
25.                 simS = simS + deltaS;
26.                 simT = simT + deltaT;
27.                 time = time+1;
28.
29.                 if (time == 100)
30.                 {
31.                     System.out.printf("Distance on %d sec: %.3f", second,simS );
32.                     System.out.println();
33.                     time = 0;
34.                     second += 1;
35.                 }
36.             }
37.     }
38.
39.     public double calculusFlight(double t)//s(t) = -0.5*g*t2 + v0*t
40.     {
41.         double s = (-0.5)*g*Math.pow(t, 2) + initV*t;
42.         System.out.printf("Final distance: %.3f Total time: %.2f" , simS,simT );
43.         System.out.println();
44.         return Math.round(s*1000)/1000.000;
45.     }
46.
47.     public double getSimulatedTime()
48.     {
49.         return simT;
50.     }
51.
52.     public double getSimulatedDistance()
53.     {
54.         return simS;
55.     }
56.
57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top