Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1.  
  2. package q2;
  3.  
  4. import java.util.*;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.Comparator;
  8.  
  9.  
  10.  
  11. public class MyInvoice implements IInvoice {
  12.  
  13. class SortTotal implements Comparator<Invoice>{
  14.  
  15. @Override
  16. public int compare(Invoice t, Invoice t1) {
  17. return Double.compare(t.total, t1.total);
  18. }
  19.  
  20. }
  21.  
  22. public Invoice f1(ArrayList<Invoice> a) {
  23. SortTotal sortT = new SortTotal();
  24. Collections.sort(a, sortT);
  25. Invoice min = Collections.min(a, sortT);
  26. return min;
  27. }
  28.  
  29. @Override
  30. public void f2(ArrayList<Invoice> a, int tt) {
  31. for (int i = 0; i<a.size(); i++){
  32. if (a.get(i).total >= 120){
  33. a.get(i).total += tt;
  34. }
  35. }
  36.  
  37. }
  38.  
  39. @Override
  40. public int f3(ArrayList<Invoice> a, int tt) {
  41. int count = 0;
  42. Iterator iter = a.iterator();
  43. while (iter.hasNext()){
  44. Invoice temp = (Invoice) iter.next();
  45. if (temp.total <= tt){
  46. count ++;
  47. }
  48. }
  49. return count;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement