-
Notifications
You must be signed in to change notification settings - Fork 0
/
evtask2.java
51 lines (44 loc) · 1019 Bytes
/
evtask2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// class
// {
// }
// class evtask2
// {
// public static void main(String[] args) {
// }
// }
import java.util.*;
import java.util.Scanner;
class Cannonball {
double velocity, position;
Cannonball(double velocity) {
this.velocity = velocity;
}
void move() {
this.position += this.velocity * 0.01;
this.velocity = this.velocity - 9.81 * 0.01;
}
double getX() {
return this.position;
}
double getY() {
return this.velocity;
}
void shoot(double initVelocity) {
for (int i = 0; this.position >= 0; i++) {
if (i % 100 == 0) {
System.out.print(this.getX() + " " + this.getY() + " ");
System.out.println( " " + (-0.5 * 9.81 * Math.pow( i / 100, 2) + initVelocity * i / 100));
}
this.move();
}
}
}
class evtask2 {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter Velocity : ");
double initVelocity = obj.nextDouble();
Cannonball c = new Cannonball(initVelocity);
c.shoot(initVelocity);
}
}