Repository navigation
Expand file tree
/
Copy pathbody.java
More file actions
70 lines (64 loc) · 1.83 KB
/
Copy pathbody.java
File metadata and controls
70 lines (64 loc) · 1.83 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.awt.Color;
/**
*
* @author Ronin
*
* The body class is a simple object used in the Gravity program.
* All bodies will have the six variables associated with them to
* run the simulation. Eventually the color variable will be
* determined by the density of the body.
*
*/
public class Body {
public Body(int mass, int size, Color color, double velX, double velY, double posX, double posY){
this.mass = mass;
this.size = size;
this.color = color;
this.velX = velX;
this.velY = velY;
this.posX = posX;
this.posY = posY;
}
//Overloaded Methods
/** This method determines if two bodies are
* the same. Because it's nearly impossible
* to have exactly the same values for everything.
* so there's a little room for error. **/
public boolean equals(Body b){
if(this.posX - b.getposx() < 5){
if(this.posY - b.getposy() < 5){
if(this.size == b.getSize()){
return true;
}
}
}
return false;
}
//Getters
public int getMass(){return mass;}
public int getSize(){return size;}
public double getvelx(){return velX;}
public double getvely(){return velY;}
public double getposx(){return posX+velX;}
public double getposy(){return posY+velY;}
public Color getColor(){return color;}
public boolean getLocked(){return lockedInPlace;}
//Setters
public void setMass(int m){mass = m;}
public void setSize(int s){size = s;}
public void setvelx(double v){velX = v;}
public void setvely(double v){velY = v;}
public void setposx(double p){posX = p;}
public void setposy(double p){posY = p;}
public void setColor(Color c){color = c;}
public void setLocked(boolean b){lockedInPlace = b;}
//Member Variables
private Color color;
private int mass;
private int size;
private double velX;
private double velY;
private double posX;
private double posY;
private boolean lockedInPlace;
}