Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch3;
- public class batterytest {
- public static void main(String[] args) {
- batteryclass AA = new batteryclass(2000);
- AA.drain(500);
- System.out.println("the charge is " + AA.getRemainingCapacity() + " mAh");
- AA.charge();
- System.out.println("the charge is " + AA.getRemainingCapacity() + " mAh");
- }
- }
- ********************************************************************************************************************************
- package ch3;
- public class batteryclass {
- private double charge;
- private double mainCharge;
- public batteryclass(double initialCharge){
- charge = initialCharge;
- mainCharge = initialCharge;}
- public void drain(double ammount){
- charge = charge - ammount;
- //return charge;
- }
- public void charge(){
- charge = mainCharge;
- }
- public double getRemainingCapacity(){
- return charge;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment