Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1.  
  2. import java.util.Random;
  3.  
  4. public class NodeApp {
  5.  
  6.  
  7. public static void main(String[] args) {
  8. Node[] nodes = new Node[200];
  9. for(int i=0; i<nodes.length; i++){
  10. nodes[i] = new Node(i, MyUtils.getClassification(), MyUtils.getMajor(), MyUtils.getMusic());
  11. }
  12.  
  13.  
  14. int[] vertices= new int[nodes.length];
  15. int [] edges= new int[vertices.length];
  16. for(int i=0; i<vertices.length; i++){
  17. int v = MyUtils.gen.nextInt(vertices.length);
  18. int w = MyUtils.gen.nextInt(nodes.length);
  19. while (v == w){
  20. w = MyUtils.gen.nextInt(vertices.length);
  21. }
  22. vertices[i] = v;
  23. edges[i] = w;
  24. }
  25. Graph G = new Graph(vertices,edges);
  26. for(int i=0; i<nodes.length; i++){
  27. System.out.println("-----------------");
  28. System.out.println(nodes[i]);
  29. System.out.println("Friends: ");
  30. for(Integer j: G.adj(i)){
  31. System.out.println(nodes[j] + " ");
  32. }
  33. }
  34.  
  35. }
  36.  
  37. }
  38.  
  39.  
  40. class MyUtils{
  41.  
  42. static Random gen = new Random();
  43.  
  44. public static void setSeed(long seed){
  45. gen = new Random(seed);
  46. }
  47.  
  48. public static void print(Object[] array){
  49. for(Object obj: array){
  50. System.out.println(obj);
  51. }
  52. }
  53.  
  54. public static Classification getClassification(){
  55. int n = gen.nextInt(4);
  56. Classification c;
  57. switch(n){
  58. case 0:
  59. c = Classification.Freshman; break;
  60. case 1:
  61. c = Classification.Sophmore; break;
  62. case 2:
  63. c = Classification.Junior; break;
  64. case 3:
  65. c = Classification.Senior; break;
  66. default:
  67. c = Classification.Freshman;
  68. }
  69. return c;
  70. }
  71.  
  72. public static Major getMajor(){
  73. int n = gen.nextInt(6);
  74. Major major;
  75. switch(n){
  76. case 0:
  77. major= Major.Biology; break;
  78. case 1:
  79. major = Major.ComputerScience; break;
  80. case 2:
  81. major = Major.Psychology; break;
  82. case 4:
  83. major = Major.PoliticalScience; break;
  84. case 5:
  85. major=Major.Music;break;
  86. default:
  87. major = Major.Biology;
  88. }
  89. return major;
  90. }
  91.  
  92. public static Music getMusic(){
  93. int n = gen.nextInt(6);
  94. Music music;
  95. switch(n){
  96. case 0:
  97. music = Music.Jazz; break;
  98. case 1:
  99. music = Music.Pop; break;
  100. case 2:
  101. music = Music.RnB; break;
  102. case 3:
  103. music = Music.Pop; break;
  104. case 4:
  105. music=Music.Rock;break;
  106. default:
  107. music= Music.other;
  108. }
  109. return music;
  110. }
  111.  
  112.  
  113. public static boolean check(Node x,Node y){
  114. if(x.classification==y.classification){
  115. return true;
  116. }
  117. return false;
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement