Repository navigation
Expand file tree
/
Copy pathCar.java
More file actions
60 lines (53 loc) · 1.44 KB
/
Copy pathCar.java
File metadata and controls
60 lines (53 loc) · 1.44 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
package StudyJava.Chap08;
class Car {
private String name;
private String number;
private int width;
private int height;
private int length;
private double x;
private double y;
private double tank;
private double fuel;
private double sfc;
Car(String name,String number, int width,int height, int length,
double tank, double fuel, double sfc){
this.name = name;
this.number= number;
this.width = width;
this.height = height;
this.length = length;
this.tank = tank;
this.fuel =fuel;
this.sfc = sfc;
}
double getX(){ return this.x; }
double getY(){ return this.y; }
double getFuel(){ return this.fuel; }
void getSpec() {
System.out.println(this.name);
System.out.println(this.number);
System.out.println(this.width);
System.out.println(this.height);
System.out.println(this.length);
System.out.println(this.tank);
System.out.println(this.fuel);
System.out.println(this.sfc);
}
boolean move(double dx, double dy){
double dist = Math.sqrt(dx * dx + dy * dy);
double f = dist/this.sfc;
if( f > this.fuel) {
return false;
}
else {
this.fuel -= f;
this.x += dx;
this.y += dy;
return true;
}
}
void refuel(double df){
this.fuel += df;
}
}