Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. //Question Number 2, part A
  2. public void split()
  3. {
  4. Node <Asset> x = this.assets;
  5. Scanner in = new Scanner(System.in);
  6. while(x!=null)
  7. {
  8. if (x.getValue().getRooms()%2==0)
  9. {
  10. System.out.println("If you want to split an asset Please type 1, else please type 0");
  11. int t = in.nextInt();
  12. if(t==1)
  13. {
  14. Asset temp = x.getValue();
  15. Asset a = new Asset(temp.getAssetCode()+"A",temp.getStreet(),temp.getRooms()/2,temp.getPrice()*0.7);
  16. Asset a = new Asset(temp.getAssetCode()+"B",temp.getStreet(),temp.getRooms()/2,temp.getPrice()*0.7);
  17. Node <Asset> a1 = new Node <Asset> (a, new Node <Asset> (b, this.assets()));
  18. this.assets = remove(this.assets, x);
  19. this.assets = a1;
  20. }
  21. }
  22. x = x.getNext();
  23. }
  24. }
  25. //Remove a Node from A List function
  26. public static Node <Asset> remove(Node <Asset> ls, Node <Asset> pos)
  27. {
  28. if (pos==ls)
  29. return pos.getNext();
  30. Node <Asset> prev = L;
  31. while (prev.getNext() != pos)
  32. prev = prev.getNext();
  33. prev.setNext(pos.getNext());
  34. return lst
  35. }
  36.  
  37. //Question Number 2, part B
  38. public static void cheap(RealEstateOffice [] of, int rooms)
  39. {
  40. String tempName = "No Office";
  41. int minPrice = Integer.MAX_VALUE;//Largest number an int can have
  42. for (int i = 0;i<of.length ;i++ )
  43. {
  44. Node <Asset> x = of[i].getAssets();
  45. while(x!=null)
  46. {
  47. if(x.getValue().getRooms() == rooms)
  48. {
  49. minPrice = x.getValue().getPrice();
  50. tempName = of[i].getOfficeName();
  51. }
  52. x = x.getNext();
  53. }
  54. }
  55. System.out.println(tempName);
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. //Question Number 3, Part A
  64. public static int count(BinNode<InfoTree> t, char x)
  65. {
  66. if (tr!=null)
  67. {
  68. int a = 0;
  69. if (tr.getValue().getTav() == x)
  70. a = 1;
  71. return a + count(t.getLeft()) + count(t.getRight());
  72. }
  73. return 0;
  74. }
  75.  
  76. public static boolean sigma(BinNode<InfoTree> bt)
  77. {
  78. if (bt==null)
  79. return true;
  80. if(bt.getValue().getNum()== count(bt,bt.getValue().getChar()))
  81. return true && sigma(bt.getLeft()) && sigma(bt.getRight());
  82. return false;
  83. }
  84.  
  85.  
  86. //Question Number 3, Part B
  87. public static int sum(BinNode<InfoTree> t)
  88. {
  89. if (t == null)
  90. return 0;
  91. int x = 0;
  92. if(t.hasLeft())
  93. if(t.getLeft().getValue()>t.getValue())
  94. x += t.getLeft().getValue()
  95. if(t.hasRight())
  96. if(t.getRight().getValue()>t.getValue())
  97. x += t.getright().getValue()
  98. return x + sum(t.getLeft()) + sum(t.getRight());
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement