Answer to Question #277452 in Java | JSP | JSF for Shan

Question #277452

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.

1
Expert's answer
2021-12-09T10:12:43-0500
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;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS