Richard_Sekol

project 3.5

Oct 5th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. package ch3;
  2.  
  3. public class batterytest {
  4. public static void main(String[] args) {
  5. batteryclass AA = new batteryclass(2000);
  6. AA.drain(500);
  7. System.out.println("the charge is " + AA.getRemainingCapacity() + " mAh");
  8. AA.charge();
  9. System.out.println("the charge is " + AA.getRemainingCapacity() + " mAh");
  10.  
  11. }
  12. }
  13. ********************************************************************************************************************************
  14.  
  15. package ch3;
  16.  
  17. public class batteryclass {
  18.  
  19. private double charge;
  20. private double mainCharge;
  21. public batteryclass(double initialCharge){
  22. charge = initialCharge;
  23. mainCharge = initialCharge;}
  24.  
  25. public void drain(double ammount){
  26. charge = charge - ammount;
  27. //return charge;
  28. }
  29. public void charge(){
  30. charge = mainCharge;
  31.  
  32. }
  33. public double getRemainingCapacity(){
  34. return charge;
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment