202k views
0 votes
Write a class Battery that models a rechargeable battery. A battery has capacity (instance variable) which can be drained. Capacity is a double value measured in milliampere hours (mAh) java

1 Answer

1 vote

A battery has capacity (instance variable) which can be drained. Capacity is a double value measured in milliampere hours (mAh) -A typical AA battery has a capacity of 2000 to 3000 mAh

Step-by-step explanation:

public class Battery

{

private double fullCharge;

private double batteryCapacity;

public Battery(doublecapacity)

{

battery Capacity = capacity;

full Charge = capacity;

}

public void drain(double amount)

{

battery Capacity = battery Capacity - amount;

}

public void charge()

{

battery Capacity = fullCharge;

}

public double get RemainingCapacity()

{

return battery Capacity;

}

}

User Don Mackenzie
by
3.8k points