Guest User

Untitled

a guest
Oct 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Lesson10Task {
  4. public static void main(String[] args) {
  5. CreditCard credit = new CreditCard(1000,false);
  6. credit.setGetMoney(15);
  7. credit.setAddMoney(50);
  8. credit.calcWithdraw();
  9. credit.calcPlus();
  10. credit.output();
  11.  
  12.  
  13. DebitCard debit = new DebitCard(1000,true,2);
  14. debit.setGetMoney(10);
  15. debit.setAddMoney(20);
  16. debit.calcWithdraw();
  17. debit.calcPlus();
  18. debit.output();
  19.  
  20.  
  21. PrivilegeCard privilege = new PrivilegeCard(100);
  22. privilege.setGetMoney(50);
  23. privilege.setAddMoney(200);
  24. privilege.calcWithdraw();
  25. privilege.calcPlus();
  26. privilege.output();
  27. }
  28. }
  29.  
  30. package com.company;
  31.  
  32. public class Card {
  33. double moneyOnCard, getMoney,addMoney,minus,plus,takenMoney,addedMoney;
  34. double percent = 0;
  35. double anotherATM = 0.5;
  36. boolean bankATM = true;
  37.  
  38. public Card(double moneyOnCard) {
  39. this.moneyOnCard = moneyOnCard;
  40. }
  41. public void setGetMoney(double getMoney) {
  42. this.getMoney = getMoney;
  43. }
  44. public void setAddMoney(double addMoney) {
  45. this.addMoney = addMoney;
  46. }
  47. }
  48.  
  49. public class CreditCard extends Card{
  50.  
  51. public CreditCard(double moneyOnCard, boolean bankATM){
  52. super(moneyOnCard);
  53. }
  54. void calcWithdraw(){
  55. if (bankATM == true) {
  56. minus = moneyOnCard - (getMoney - percent);
  57.  
  58. }
  59. else{
  60. minus = moneyOnCard - getMoney - ((getMoney * anotherATM)/100);
  61. }
  62. takenMoney = moneyOnCard - minus;
  63. }
  64. void calcPlus(){
  65. plus = moneyOnCard + addMoney;
  66. addedMoney = plus - moneyOnCard;
  67. }
  68. void output(){
  69. System.out.println("=== Credit Card ===");
  70. System.out.println("Money count after withdraw: " + minus);
  71. System.out.println("Taken money: " + takenMoney);
  72. System.out.println();
  73. System.out.println("Money count after deposit: " + plus);
  74. System.out.println("Added money: " + addedMoney);
  75. System.out.println();
  76. System.out.println();
  77. }
  78. }
  79.  
  80. package com.company;
  81.  
  82. public class DebitCard extends Card {
  83. double deposit = 1;
  84. double withdrawWithDebit;
  85. int monthNumber;
  86.  
  87. public DebitCard(int moneyOnCard, boolean bankATM, int monthNumber) {
  88. super(moneyOnCard);
  89. this.monthNumber = monthNumber;
  90. }
  91.  
  92. void calcWithdraw() {
  93. System.out.println("=== Debit Card ===");
  94. System.out.println("==Money count with 1% deposit==");
  95. System.out.println();
  96. if (bankATM == true) {
  97. withdrawWithDebit = moneyOnCard + (moneyOnCard * (deposit / 100 / 12) * monthNumber) - getMoney;
  98. } else {
  99. withdrawWithDebit = moneyOnCard + (moneyOnCard * (deposit / 100 / 12) * monthNumber) - getMoney - ((getMoney * (anotherATM / 100)));
  100. }
  101. takenMoney = moneyOnCard - withdrawWithDebit;
  102. }
  103. void calcPlus(){
  104. plus = (moneyOnCard + addMoney) + (addMoney *((deposit/100/12)*monthNumber));
  105. addedMoney = plus - moneyOnCard;
  106.  
  107. }
  108. void output(){
  109. System.out.println("Money count after withdraw: " +withdrawWithDebit + " in a " + monthNumber + " month");
  110. System.out.println("Taken money + deposit: " + takenMoney);
  111. System.out.println();
  112. System.out.println("Money count after deposit: " + plus);
  113. System.out.println("Added money + deposit: " + addedMoney + " in a " + monthNumber + " month");
  114. System.out.println();
  115. System.out.println();
  116. }
  117. }
  118.  
  119. package com.company;
  120.  
  121. public class PrivilegeCard extends Card {
  122. public PrivilegeCard (double moneyOnCard){
  123. super(moneyOnCard);
  124. }
  125. void calcWithdraw() {
  126. minus = moneyOnCard - (getMoney - percent);
  127. takenMoney = moneyOnCard - minus;
  128. }
  129. void calcPlus() {
  130. plus = moneyOnCard + addMoney;
  131. addedMoney = plus - moneyOnCard;
  132. }
  133. void output() {
  134. System.out.println("=== Privilege Card ===");
  135. System.out.println("Money count after withdraw: " + minus);
  136. System.out.println("Taken money: " + takenMoney);
  137. System.out.println();
  138. System.out.println("Money count after deposit: " + plus);
  139. System.out.println("Added money: " + addedMoney);
  140. System.out.println();
  141. }
  142. }
  143.  
  144. === Credit Card ===
  145. Money count after withdraw: 985.0
  146. Taken money: 15.0
  147.  
  148. Money count after deposit: 1050.0
  149. Added money: 50.0
  150.  
  151.  
  152. === Debit Card ===
  153. ==Money count with 1% deposit==
  154.  
  155. Money count after withdraw: 991.6666666666666 in a 2 month
  156. Taken money + deposit: 8.333333333333371
  157.  
  158. Money count after deposit: 1020.0333333333333
  159. Added money + deposit: 20.033333333333303 in a 2 month
  160.  
  161.  
  162. === Privilege Card ===
  163. Money count after withdraw: 50.0
  164. Taken money: 50.0
  165.  
  166. Money count after deposit: 300.0
  167. Added money: 200.0
  168.  
  169.  
  170. It is
Add Comment
Please, Sign In to add comment