Advertisement
sshomette

Untitled

Oct 6th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. static class extraFraction{
  2. private int num;
  3. private int denom;
  4. private double decimal;
  5.  
  6. private extraFraction(){
  7. num = 0;
  8. denom = 1;
  9. decimal = 0;
  10. }
  11. public extraFraction(int n, int d)
  12. {
  13. num = n;
  14. denom = d;
  15. decimal = ((double)n)/d;
  16. }
  17. public double getDecimal()
  18. {
  19. return decimal;
  20. }
  21. public int gn(){
  22. return num;
  23. }
  24. public int gd(){
  25. return denom;
  26. }
  27. public String toString()
  28. {
  29. String s1;
  30. s1 = ""+num + "/" + denom;
  31. return s1;
  32. }
  33. }
  34.  
  35.  
  36. public static void FractionSort()
  37. {
  38. ArrayList<extraFraction> values = new ArrayList<extraFraction>();
  39. for (int i = 0; i < list.size(); i++)
  40. {
  41. int n = list.get(i).getNumerator();
  42. int d = list.get(i).getDenominator();
  43. extraFraction newer = new extraFraction(n,d);
  44. values.add(newer);
  45. }
  46. for (int i = 0; i < list.size(); i++)
  47. {
  48. for (int j = 0; j <= i; j++)
  49. {
  50. if (values.get(j).getDecimal()>values.get(i).getDecimal())
  51. {
  52. extraFraction oldfrac = values.set(j+1, values.get(j));
  53. values.set(j+1, values.get(j));
  54. values.add(j, oldfrac);
  55. }
  56.  
  57. }
  58. }
  59. for (int i = 0 ; i < list.size(); i++)
  60. {
  61. System.out.println((i + 1) + ".\t" + values.get(i));
  62. }
  63.  
  64. r.pause();
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement