Car is an object that helps us in transportation. Analyze the concept and identify the data members and methods that should be included in Car class.
public class Car {
private int passengerCapacity;
private int numberOfPassengers;
private double carryingCapacity;
private double fuelConsumption;
private double currentWeight;
public Car(int passengerCapacity, double carryingCapacity, double fuelConsumption, double currentWeight) {
this.passengerCapacity = passengerCapacity;
this.carryingCapacity = carryingCapacity;
this.fuelConsumption = fuelConsumption;
this.currentWeight = currentWeight;
this.numberOfPassengers = 0;
}
public boolean addPassengers(int numberOfPassengers) {
if (this.numberOfPassengers + numberOfPassengers <= passengerCapacity) {
this.numberOfPassengers += numberOfPassengers;
return true;
}
return false;
}
public boolean addWeight(double weight) {
if (currentWeight + weight <= carryingCapacity) {
currentWeight += weight;
return true;
}
return false;
}
public int getPassengerCapacity() {
return passengerCapacity;
}
public int getNumberOfPassengers() {
return numberOfPassengers;
}
public double getCarryingCapacity() {
return carryingCapacity;
}
public double getFuelConsumption() {
return fuelConsumption;
}
public double getCurrentWeight() {
return currentWeight;
}
}
Comments
Leave a comment