Advertisement
Parasect

AccMain

Oct 19th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main
  4. {
  5. public static void main(String[] args)
  6. {
  7. /*
  8. Scanner in = new Scanner(System.in);
  9. double t = 0;
  10. Account a[] = new Account[20];
  11. for (int i = 0; i<20; i++){
  12. a[i] = new Account(in.nextLine(), (int)(Math.random()*1001.0));
  13. t += a[i].getBalance();
  14. }
  15. double avg = t/20;
  16. for (int i = 0; i<20; i++){
  17. if(a[i].getBalance()>avg){
  18. System.out.println(a[i].toString());
  19. }
  20. }
  21. */
  22. /*//SORT BY BALANCE
  23.  
  24. Account b = new Account("yo",100);
  25. Account c = new Account("k",300);
  26. Account d = new Account("d", 200);
  27. Account e = new Account("m",50);
  28. Account [] x = {b,c,d,e};
  29. sortByBalance(x);
  30. for (int i = 0; i<x.length;i++){
  31. System.out.println(x[i]);
  32. }
  33. */
  34.  
  35. /*//ROBIN HOOD
  36. Account rich = new Account("rich", 300);
  37. Account norm = new Account("norm", 250);
  38. Account poor = new Account("poor", 200);
  39. Account[] robin = {rich, poor, norm};
  40. robinHood(robin);
  41. System.out.println(rich);
  42. System.out.println(poor);
  43. System.out.println(norm);
  44. */
  45.  
  46. /*//TAKE COMISSION
  47. Account rich = new Account("rich", 300);
  48. Account norm = new Account("norm", 250);
  49. Account poor = new Account("poor", 200);
  50. Account[] taxes = {rich, poor, norm};
  51. System.out.println(takeCommission(taxes, 10));
  52. */
  53.  
  54. /*//CHECK
  55. Account rich = new Account("rich", 300);
  56. Account norm = new Account("norm", 250);
  57. Account poor = new Account("poor", 200);
  58. Account[] t = {rich, poor, norm};
  59. System.out.println(check(t, 1001));
  60. */
  61.  
  62. //PRINT CANNOT BE CHECKED AS ALL DATES ARE SAME (TODAY)
  63.  
  64. /*//COUNT
  65. Account rich = new Account("rich", 300);
  66. Account norm = new Account("norm", 250);
  67. Account poor = new Account("poor", 200);
  68. Account[] t = {rich, poor, norm};
  69. System.out.println(count(t,2014));
  70. */
  71.  
  72. //OLDEST CANNOT BE CHECKED AS ALL DATES ARE SAME (TODAY)
  73.  
  74. /*//CHECK
  75. Account rich = new Account("rich", 3200);
  76. Account norm = new Account("rich", 2250);
  77. Account poor = new Account("poor", 200);
  78. Account[] t = {rich, poor, norm};
  79. int[] a = check(t, "rich");
  80. for (int i = 0; i < a.length; i++) {
  81. System.out.println(a[i]);
  82. }
  83. */
  84. }
  85.  
  86. public static void robinHood(Account[] arr){
  87. double max = 0;
  88. double min = Integer.MAX_VALUE;
  89. int num1 = 0;
  90. int num2 = 0;
  91. for(int i = 0; i<arr.length; i++){
  92. if (arr[i].getBalance() > max){
  93. max= arr[i].getBalance();
  94. num1 = i;
  95. }
  96. if (arr[i].getBalance() < min){
  97. min = arr[i].getBalance();
  98. num2=i;
  99. }
  100. }
  101. arr[num1].transfer(arr[num2], arr[num1].getBalance()/2);
  102. }
  103.  
  104. public static double takeCommission(Account[] arr, int percent){
  105. double emla = 0;
  106. for (int i = 0; i<arr.length;i++){
  107. double z = arr[i].getBalance()/100*percent;
  108. emla+=z;
  109. }
  110. return emla;
  111. }
  112.  
  113. public static boolean check(Account[] arr, int accNum){
  114. for (int i = 0; i<arr.length; i++){
  115. if(arr[i].getAccNum()==accNum){
  116. return true;
  117. }
  118. }
  119. return false;
  120. }
  121. public static void print(Account[] arr, Date date){
  122.  
  123. for (int i = 0; i<arr.length;i++){
  124. if(date.compareTo(arr[i].getOpenDate()) == -1){
  125. System.out.println(arr[i].toString());
  126. }
  127. }
  128. }
  129. public static int count(Account[] arr, int year){
  130. int c = 0;
  131. for(int i = 0; i<arr.length; i++){
  132. if (arr[i].getOpenDate().getYear() == year){
  133. c++;
  134. }
  135. }
  136. return c;
  137. }
  138. public static Account oldest(Account[] arr){
  139. int y = Integer.MAX_VALUE;
  140. int z = 0;
  141. for(int i = 0; i<arr.length; i++){
  142. if(arr[i].getOpenDate().getYear() < y){
  143. y = arr[i].getOpenDate().getYear();
  144. z = i;
  145. }
  146. }
  147. return arr[z];
  148. }
  149. public static int[] check(Account[] arr, String name){
  150. int []x = new int[arr.length];
  151. for(int i = 0; i<arr.length; i++){
  152. if(arr[i].getOwnerName().equals(name)){
  153. x[i] = arr[i].getAccNum();
  154. }
  155. }
  156.  
  157. return x;
  158.  
  159. }
  160. public static void sortByBalance(Account[] arr){
  161. boolean isFinished = true;
  162. while(isFinished){
  163. isFinished = false;
  164. for(int i = 0; i<arr.length-1;i++){
  165. if(arr[i+1].getBalance()<arr[i].getBalance()){
  166. Account temp = arr[i];
  167. arr[i] = arr[i+1];
  168. arr[i+1] = temp;
  169. isFinished = true;
  170. }
  171. }
  172. }
  173. }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement