-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicle.java
More file actions
125 lines (118 loc) · 3.42 KB
/
Copy pathVehicle.java
File metadata and controls
125 lines (118 loc) · 3.42 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class Vehicle{
int passengers;
int fuelcap;
int mpg;
void range(){
System.out.println("Quang duong di duoc la " + fuelcap*mpg +"dam");
}
int rangever_2(){
return mpg*fuelcap;
}
double fuelneeded(int miles){
return (double) miles/mpg;
}
Vehicle (int p, int f, int m){
passengers=p;
fuelcap=f;
mpg=m;
}
}
class AddMeth{
public static void main(String args[]) {
Vehicle minivan =new Vehicle();
Vehicle sportcar=new Vehicle();
minivan.fuelcap=16;
minivan.passengers=7;
minivan.mpg=21;
sportcar.passengers=2;
sportcar.fuelcap=14;
sportcar.mpg=12;
minivan.range();
sportcar.range();
}
}
class Vehicle_demo{
public static void main(String args[]) {
Vehicle minivan=new Vehicle();
int range;
minivan.fuelcap=16;
minivan.passengers=7;
minivan.mpg=21;
range=minivan.mpg*minivan.fuelcap;
System.out.println("Minivan co the cho" +minivan.passengers+ "hanh khach trong quang duong dai"+range+ "dam" );
}
}
class RetMeth{
public static void main(String args[]) {
Vehicle minivan = new Vehicle();
Vehicle sportcar=new Vehicle();
int range1,range2;
minivan.fuelcap=16;
minivan.mpg=21;
minivan.passengers=7;
sportcar.fuelcap=14;
sportcar.mpg=12;
sportcar.passengers=2;
range1=minivan.rangever_2();
range2=sportcar.rangever_2();
System.out.println(range1);
System.out.println(range2);
}
}
class CompFuel{
public static void main(String args[]) {
Vehicle minivan =new Vehicle();
Vehicle sportcar=new Vehicle();
double gallons;
int dist=252;
minivan.passengers=7;
minivan.fuelcap=16;
minivan.mpg=21;
sportcar.passengers=2;
sportcar.fuelcap=14;
sportcar.mpg=12;
gallons=minivan.fuelneeded(dist);
System.out.println(gallons);
gallons=sportcar.fuelneeded(dist);
System.out.println(gallons);
}
}
class VehConsDemo{
public static void main(String args[]) {
Vehicle minivan =new Vehicle(7, 16, 21);
Vehicle sportcar= new Vehicle(2, 14, 12);
double gallons;
int dist=252;
gallons=minivan.fuelneeded(dist);
System.out.println(gallons);
gallons=sportcar.fuelneeded(dist);
System.out.println(gallons);
}
}
class Truck extends Vehicle{
private int cargocap;
Truck(int p, int f, int m, int c){
super(p, f, m);
cargocap=c;
}
int getCargo(){
return cargocap;
}
void putCargo(int c){
cargocap=c;
}
}
class TruckDemo{
public static void main(String args[]) {
Truck semi=new Truck(2, 200, 7, 44000);
Truck pickup=new Truck(3, 28, 15, 2000);
double gallons;
int dist=252;
gallons=semi.fuelneeded(dist);
System.out.println("Semi co the cho duoc: " + semi.getCargo() + "pound");
System.out.println("de di duoc" + dist + "dam semi can " + gallons + "gallons nhien lieu");
gallons=pickup.fuelneeded(dist);
System.out.println("Pickup co the cho duoc: " + pickup.getCargo() + "pound");
System.out.println("de di duoc " + dist + "dam pickup can " + gallons + "gallons nhien lieu");
}
}