Advertisement
Richard_Sekol

ex3.3&3.4 main and class

Oct 2nd, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package richards;
  2.  
  3.  
  4. public class ex33 {
  5. public static void main(String[] args) {
  6. BankAccountididntstealfrombook testAcct = new BankAccountididntstealfrombook(1000);
  7. testAcct.Withdraw(500);
  8. testAcct.Withdraw(400);
  9. System.out.println(testAcct.GetBalance());
  10. System.out.println("expected result: 100");
  11. //This part below for Ex3.4
  12. testAcct.addInterest(.10);
  13. System.out.println("the ammount with interest is " + testAcct.GetBalance());
  14. }
  15. }
  16.  
  17.  
  18. ###################################################################################################################################CLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASS
  19.  
  20. package richards;
  21.  
  22. public class BankAccountididntstealfrombook {
  23.  
  24. private double balance;
  25.  
  26. /**
  27. * constructor for initial balance of balance
  28. */
  29. public BankAccountididntstealfrombook(double initialValue){
  30. balance = initialValue;
  31. }
  32.  
  33. /**
  34. * deposit some amount into the account
  35. * @param amount
  36. */
  37. public void Deposit(double amount){
  38. balance = balance + amount;
  39. }
  40.  
  41. /**
  42. * withdraw some amount from the account
  43. * @param amount
  44. */
  45. public void Withdraw(double amount){
  46. balance = balance - amount;
  47. }
  48.  
  49. /**
  50. * get the balance so you can print it or whatever
  51. * @return
  52. */
  53. public double GetBalance(){
  54. return balance;
  55. }
  56.  
  57. public void addInterest(double rate)
  58. {
  59. double newBalance;
  60. newBalance = balance;
  61. balance = newBalance + balance * rate;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement