-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
68 lines (56 loc) · 1.58 KB
/
Copy pathCar.java
File metadata and controls
68 lines (56 loc) · 1.58 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
import java.util.*;
public class Car{
int noOFWheels;
String color;
float maxSpeed; //instance variable
float CurrentFuel;
int noOfSeats;
public void Drive(){
if(CurrentFuel == 0){
System.out.println("Fuel Empty....");
}
else if(CurrentFuel < 5){
System.out.println("Car is in reserved mode, Please refil");
CurrentFuel--;
}
else{
System.out.println("Car is driving");
CurrentFuel--;
}
}
public void addFuel(float fuel){
CurrentFuel += fuel;
}
public void addColor(String color){
this.color= color;
}
public String getColor(){
return this.color;
}
public float getCurrentFuel(){
return CurrentFuel;
}
public void wheels(int noOFWheelsheels){
this.noOFWheels = noOFWheels;
}
public int getWheels(){
return this.noOFWheels;
}
public static void main(String args[]){
Car swift = new Car(); //reference of class
Car nano = new Car();
swift.addFuel(6);
// swift.Drive();
// swift.Drive();
// swift.Drive();
nano.addFuel(5);
nano.wheels(4);
nano.Drive();
nano.Drive();
nano.addColor("red");
// System.out.println(swift.getCurrentFuel());
System.out.println(nano.getCurrentFuel());
System.out.println( "Car color is "+nano.getColor());
System.out.println("Car has"+nano.getWheels());
}
}