Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // Class 1. Constructor Class
  2. package battery;
  3.  
  4. /**
  5. * Coder: @GioLopera
  6. */
  7. public class Battery {
  8.  
  9. private double maxCapacity;
  10. private double curCapacity;
  11.  
  12. public Battery(double capacity)
  13. {
  14. maxCapacity = capacity;
  15. curCapacity = maxCapacity;
  16. }
  17.  
  18. public void drain(double amount)
  19. {
  20. curCapacity -= amount;
  21. }
  22.  
  23. public void charge()
  24. {
  25. curCapacity = maxCapacity;
  26. }
  27.  
  28. public double getRemainingCapacity()
  29. {
  30. return curCapacity;
  31. }
  32.  
  33. }
  34.  
  35. //Class 2. Tester Class
  36.  
  37. package battery;
  38.  
  39. /**
  40. *
  41. * Author: @GioLopera
  42. */
  43. public class BatteryTester
  44. {
  45. public static void main(String[] args)
  46. {
  47. Battery battery = new Battery(100.0);
  48.  
  49. System.out.println(battery.getRemainingCapacity());
  50. System.out.println("Expected: 100.0");
  51.  
  52. battery.drain(23.4);
  53. battery.drain(9.7);
  54.  
  55. System.out.println(battery.getRemainingCapacity());
  56. System.out.println("Expected: 66.9");
  57.  
  58. battery.charge();
  59. System.out.println(battery.getRemainingCapacity());
  60. System.out.println("Expected: 100.0");
  61.  
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement