Hey, I'm starting a new thread since my thread "Using Random class" may or may not have the error due to the class Random. More likely it's something wrong with one of my ArrayLists.
package DiscreteMathProject; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.Random; import java.util.Set; public class MainClass { private String[] studentNames; private Student[] students; private Class[] classes; private String[] classNames; private ArrayList<Student> aList2; private Random[] random; PrintWriter outFile; public MainClass() throws FileNotFoundException { outFile = new PrintWriter("classes.txt"); classes = new Class[35]; studentNames = new String[500]; students = new Student[500]; studentNames[0] = "Joe McDonald"; studentNames[1] = "Paul Adcock"; studentNames[2] = "Darth Vader"; studentNames[3] = "Peter Parker"; studentNames[4] = "Abraham Lincoln"; studentNames[5] = "Albert Einstein"; studentNames[6] = "Spongebob Squarepants"; studentNames[7] = "James Bond"; studentNames[8] = "Sherlock Holmes"; studentNames[9] = "John Wayne"; studentNames[10] = "Walter Payton"; studentNames[11] = "George Herman (Babe) Ruth"; studentNames[12] = "Susan B. Anthony"; studentNames[13] = "Martin Luther"; studentNames[14] = "Julius Ceasar"; studentNames[15] = "Adolf Hitler"; studentNames[16] = "Joseph Stalin"; studentNames[17] = "Fidel Castro"; studentNames[18] = "Ivan The Terrible"; studentNames[19] = "Jabba The Hutt"; studentNames[20] = "Luke Skywalker"; studentNames[21] = "Emperor Palpatine"; studentNames[22] = "Thomas Edison"; studentNames[23] = "Benjamin Franklin"; studentNames[24] = "Judas Iscariot"; studentNames[25] = "King David"; studentNames[26] = "Blaise Pascal"; studentNames[27] = "John Watson"; studentNames[28] = "James Watt"; studentNames[29] = "Henry Ford"; studentNames[30] = "Michael Jackson"; studentNames[31] = "Mohatma Ghandi"; studentNames[32] = "Emperor Mao"; studentNames[33] = "Robin of Locksley (Robin Hood)"; studentNames[34] = "King Richard The Lionhearted"; studentNames[35] = "Harry Potter"; studentNames[36] = "John Smith"; studentNames[37] = "King John"; studentNames[38] = "William The Conqueror"; studentNames[39] = "Bloody Mary"; studentNames[40] = "Johnny Cash"; studentNames[41] = "Sargon of Akkad"; studentNames[42] = "Prince Absalom"; studentNames[43] = "Eustace Clarence"; studentNames[44] = "Ronald Weasley"; studentNames[45] = "Rosa Parks"; studentNames[46] = "Sandra Day O'Connor"; studentNames[47] = "Queen Lucy Pevensie"; studentNames[48] = "John The Apostle"; studentNames[49] = "Kevin McAlister"; studentNames[50] = "Alex Pruitt"; studentNames[51] = "Guy Fawkes"; studentNames[52] = "Queen Heshepshut"; studentNames[53] = "King Ramases"; studentNames[54] = "King Xerxes of Persia"; studentNames[55] = "Nathan Hale"; studentNames[56] = "Patrick Henry"; studentNames[57] = "Jacob Marley"; studentNames[58] = "Ebenezer Scrooge"; studentNames[59] = "Saint Augustine"; studentNames[60] = "John Lennon"; studentNames[61] = "Forrest Gump"; studentNames[62] = "Jenny Gump"; studentNames[63] = "Luitenant Dan"; studentNames[64] = "John Q. Public"; studentNames[65] = "Bill Gates"; studentNames[66] = "Harriet Tubman"; studentNames[67] = "Sojourner Truth"; studentNames[68] = "Malcom Little(Malcom X)"; studentNames[69] = "Leonardo D. Caprio"; studentNames[70] = "Jack Philps"; studentNames[71] = "Paul Revere"; studentNames[72] = "Becky Thatcher"; studentNames[73] = "Tom Sawyer"; studentNames[74] = "Samual Clemmons(Mark Twain)"; studentNames[75] = "George Washington Carver"; studentNames[76] = "Paul Bunyan"; studentNames[77] = "Huck Finn"; studentNames[78] = "Picos Bill"; studentNames[79] = "Mark Anthony"; studentNames[80] = "Queen Cleopatra"; studentNames[81] = "Anne Frank"; studentNames[82] = "Eli Wesel"; studentNames[83] = "Eddie Brock"; studentNames[84] = "Thorin Oakenshield"; studentNames[85] = "Bilbo Bagins"; studentNames[86] = "Frodo Baggins"; studentNames[87] = "Sam Gamagee"; studentNames[88] = "Gandalf the Gray"; studentNames[89] = "Sauraman the Wise"; studentNames[90] = "King George III"; studentNames[91] = "William Wilberforce"; studentNames[92] = "Merry Brandybuck"; studentNames[93] = "Martin Luther King Jr."; studentNames[94] = "Jackie Robinson"; studentNames[95] = "Sherwim Williams"; studentNames[96] = "John Menard"; studentNames[97] = "Chrisopher Columbus"; studentNames[98] = "Genghis Khan"; studentNames[99] = "Atilla The Hun"; studentNames[100] = "Al Capone"; studentNames[101] = "Napolean Bonepart"; studentNames[102] = "Marie Antionette"; studentNames[103] = "King Louis XVII"; studentNames[104] = "Napolean Blownapart"; studentNames[105] = "Yesser Arafat"; studentNames[106] = "Al Gore"; studentNames[107] = "Benedict Arnold"; studentNames[108] = "Tim Allen"; studentNames[109] = "George W. Bush"; for (int x = 110; x < 500; x++) { studentNames[x] = "Student " + x; } for (int y = 0; y < 500; y++) { students[y] = new Student(studentNames[y]); } classNames = new String[35]; classNames[0] = "Sleeping 101"; classNames[1] = "Partying 202"; classNames[2] = "Discrete Math"; classNames[3] = "Rocket Science"; classNames[4] = "Introduction to Data Structures"; classNames[5] = "Skipping 303"; classNames[6] = "Creative Writing"; classNames[7] = "Introduction to Technical Communication"; classNames[8] = "Easy Class"; classNames[9] = "Surviving College"; classNames[10] = "How To Outsmart the Profs"; classNames[11] = "Astronomy"; classNames[12] = "Thermodynamics"; classNames[13] = "Long-winded Lectures 404"; classNames[14] = "System Design"; classNames[15] = "Physics"; classNames[16] = "Chemistry"; classNames[17] = "Tutoring"; classNames[18] = "Politics 204"; classNames[19] = "Very Hard Class"; classNames[20] = "Introduction to Java Programming"; classNames[21] = "Biology"; classNames[22] = "Physical Education"; classNames[23] = "Databases"; classNames[24] = "World History"; classNames[25] = "Philosophy"; classNames[26] = "Daydreaming 404"; classNames[27] = "Eating 208"; classNames[28] = "Kung Fu Fighting"; classNames[29] = "Religion"; classNames[30] = "Film Making"; classNames[31] = "How to Understand Women(Sorta) 467"; classNames[32] = "How to Understand Men(Sorta) 468"; classNames[33] = "TV Studio 303"; classNames[34] = "Architecture"; for (int z = 0; z < 35; z++) { classes[z] = new Class(classNames[z]); } System.out.println(classes[0].getName()); Random rand1 = new Random(); Set<Student> mix1 = new TreeSet<Student>(); Student[] st1 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[0].getSize(); i++ ){ int rN1 = rand1.nextInt(classes[0].getSize()); while ( mix1.contains(students[rN1]) ){//already chose rN1= rand1.nextInt(classes[0].getSize());//get another } mix1.add(students[rN1]); mix1.toArray(st1); st1 = mix1.toArray(st1); } for (int k = 0; k < classes[0].getSize() ; k++) { classes[0].addStudents(st1[k]); } System.out.println(classes[0].toString()); outFile.println(classes[0].toString()); Random rand2 = new Random(); Set<Student> mix2 = new TreeSet<Student>(); Student[] st2 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[1].getSize(); i++ ){ int rN2 = rand2.nextInt(classes[1].getSize()); while ( mix2.contains(students[rN2]) ){//already chose rN2= rand2.nextInt(classes[1].getSize());//get another } mix2.add(students[rN2]); mix2.toArray(st2); st2 = mix2.toArray(st2); } for (int k = 0; k < classes[1].getSize() ; k++) { classes[1].addStudents(st2[k]); } System.out.println(classes[1].toString()); outFile.println(classes[1].toString()); Random rand3 = new Random(); Set<Student> mix3 = new TreeSet<Student>(); Student[] st3 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[2].getSize(); i++ ){ int rN3 = rand3.nextInt(classes[2].getSize()); while ( mix3.contains(students[rN3]) ){//already chose rN3= rand3.nextInt(classes[2].getSize());//get another } mix3.add(students[rN3]); mix3.toArray(st3); st3 = mix3.toArray(st3); } for (int k = 0; k < classes[2].getSize() ; k++) { classes[2].addStudents(st3[k]); } System.out.println(classes[2].toString()); outFile.println(classes[2].toString()); Random rand4 = new Random(); Set<Student> mix4 = new TreeSet<Student>(); Student[] st4 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[3].getSize(); i++ ){ int rN4 = rand4.nextInt(classes[3].getSize()); while ( mix4.contains(students[rN4]) ){//already chose rN4= rand4.nextInt(classes[3].getSize());//get another } mix4.add(students[rN4]); mix4.toArray(st4); st4 = mix4.toArray(st4); } for (int k = 0; k < classes[3].getSize() ; k++) { classes[3].addStudents(st4[k]); } System.out.println(classes[3].toString()); outFile.println(classes[3].toString()); Random rand5 = new Random(); Set<Student> mix5 = new TreeSet<Student>(); Student[] st5 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[4].getSize(); i++ ){ int rN5 = rand5.nextInt(classes[4].getSize()); while ( mix5.contains(students[rN5]) ){//already chose rN5= rand5.nextInt(classes[4].getSize());//get another } mix5.add(students[rN5]); mix5.toArray(st5); st5 = mix5.toArray(st5); } for (int k = 0; k < classes[4].getSize() ; k++) { classes[4].addStudents(st5[k]); } System.out.println(classes[4].toString()); outFile.println(classes[4].toString()); Random rand6 = new Random(); Set<Student> mix6 = new TreeSet<Student>(); Student[] st6 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[5].getSize(); i++ ){ int rN6 = rand6.nextInt(classes[5].getSize()); while ( mix6.contains(students[rN6]) ){//already chose rN6= rand6.nextInt(classes[5].getSize());//get another } mix6.add(students[rN6]); mix6.toArray(st6); st6 = mix6.toArray(st6); } for (int k = 0; k < classes[5].getSize() ; k++) { classes[5].addStudents(st6[k]); } System.out.println(classes[5].toString()); outFile.println(classes[5].toString()); Random rand7 = new Random(); Set<Student> mix7 = new TreeSet<Student>(); Student[] st7 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[6].getSize(); i++ ){ int rN7 = rand7.nextInt(classes[6].getSize()); while ( mix7.contains(students[rN7]) ){//already chose rN7= rand7.nextInt(classes[6].getSize());//get another } mix7.add(students[rN7]); mix7.toArray(st7); st7 = mix7.toArray(st7); } for (int k = 0; k < classes[6].getSize() ; k++) { classes[6].addStudents(st7[k]); } System.out.println(classes[6].toString()); outFile.println(classes[6].toString()); Random rand8 = new Random(); Set<Student> mix8 = new TreeSet<Student>(); Student[] st8 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[7].getSize(); i++ ){ int rN8 = rand8.nextInt(classes[7].getSize()); while ( mix8.contains(students[rN8]) ){//already chose rN8= rand8.nextInt(classes[7].getSize());//get another } mix8.add(students[rN8]); mix8.toArray(st8); st8 = mix8.toArray(st8); } for (int k = 0; k < classes[7].getSize() ; k++) { classes[7].addStudents(st8[k]); } System.out.println(classes[7].toString()); outFile.println(classes[7].toString()); Random rand9 = new Random(); Set<Student> mix9 = new TreeSet<Student>(); Student[] st9 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[8].getSize(); i++ ){ int rN9 = rand9.nextInt(classes[8].getSize()); while ( mix9.contains(students[rN9]) ){//already chose rN9= rand9.nextInt(classes[8].getSize());//get another } mix9.add(students[rN9]); mix9.toArray(st9); st9 = mix9.toArray(st9); } for (int k = 0; k < classes[8].getSize() ; k++) { classes[8].addStudents(st9[k]); } System.out.println(classes[8].toString()); outFile.println(classes[8].toString()); Random rand10 = new Random(); Set<Student> mix10 = new TreeSet<Student>(); Student[] st10 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[9].getSize(); i++ ){ int rN10 = rand10.nextInt(classes[9].getSize()); while ( mix10.contains(students[rN10]) ){//already chose rN10= rand10.nextInt(classes[9].getSize());//get another } mix10.add(students[rN10]); mix10.toArray(st10); st10 = mix10.toArray(st10); } for (int k = 0; k < classes[9].getSize() ; k++) { classes[9].addStudents(st10[k]); } System.out.println(classes[9].toString()); outFile.println(classes[9].toString()); Random rand11 = new Random(); Set<Student> mix11 = new TreeSet<Student>(); Student[] st11 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[10].getSize(); i++ ){ int rN11 = rand11.nextInt(classes[10].getSize()); while ( mix11.contains(students[rN11]) ){//already chose rN11= rand11.nextInt(classes[10].getSize());//get another } mix11.add(students[rN11]); mix11.toArray(st11); st11 = mix11.toArray(st11); } for (int k = 0; k < classes[10].getSize() ; k++) { classes[10].addStudents(st11[k]); } System.out.println(classes[10].toString()); outFile.println(classes[10].toString()); Random rand12 = new Random(); Set<Student> mix12 = new TreeSet<Student>(); Student[] st12 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[11].getSize(); i++ ){ int rN12 = rand12.nextInt(classes[11].getSize()); while ( mix12.contains(students[rN12]) ){//already chose rN12= rand12.nextInt(classes[11].getSize());//get another } mix12.add(students[rN12]); mix12.toArray(st12); st12 = mix12.toArray(st12); } for (int k = 0; k < classes[11].getSize() ; k++) { classes[11].addStudents(st12[k]); } System.out.println(classes[11].toString()); outFile.println(classes[11].toString()); Random rand13 = new Random(); Set<Student> mix13 = new TreeSet<Student>(); Student[] st13 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[12].getSize(); i++ ){ int rN13 = rand13.nextInt(classes[12].getSize()); while ( mix13.contains(students[rN13]) ){//already chose rN13= rand13.nextInt(classes[12].getSize());//get another } mix13.add(students[rN13]); mix13.toArray(st13); st13 = mix13.toArray(st13); } for (int k = 0; k < classes[12].getSize() ; k++) { classes[12].addStudents(st13[k]); } System.out.println(classes[12].toString()); outFile.println(classes[12].toString()); Random rand14 = new Random(); Set<Student> mix14 = new TreeSet<Student>(); Student[] st14 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[13].getSize(); i++ ){ int rN14 = rand14.nextInt(classes[13].getSize()); while ( mix14.contains(students[rN14]) ){//already chose rN14= rand14.nextInt(classes[13].getSize());//get another } mix14.add(students[rN14]); mix14.toArray(st14); st14 = mix14.toArray(st14); } for (int k = 0; k < classes[13].getSize() ; k++) { classes[13].addStudents(st14[k]); } System.out.println(classes[13].toString()); outFile.println(classes[13].toString()); Random rand15 = new Random(); Set<Student> mix15 = new TreeSet<Student>(); Student[] st15 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[14].getSize(); i++ ){ int rN15 = rand15.nextInt(classes[14].getSize()); while ( mix15.contains(students[rN15]) ){//already chose rN15= rand15.nextInt(classes[14].getSize());//get another } mix15.add(students[rN15]); mix15.toArray(st15); st15 = mix15.toArray(st15); } for (int k = 0; k < classes[14].getSize() ; k++) { classes[14].addStudents(st15[k]); } System.out.println(classes[14].toString()); outFile.println(classes[14].toString()); Random rand16 = new Random(); Set<Student> mix16 = new TreeSet<Student>(); Student[] st16 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[15].getSize(); i++ ){ int rN16 = rand16.nextInt(classes[15].getSize()); while ( mix16.contains(students[rN16]) ){//already chose rN16= rand16.nextInt(classes[15].getSize());//get another } mix16.add(students[rN16]); mix16.toArray(st16); st16 = mix16.toArray(st16); } for (int k = 0; k < classes[15].getSize() ; k++) { classes[15].addStudents(st16[k]); } System.out.println(classes[15].toString()); outFile.println(classes[15].toString()); Random rand17 = new Random(); Set<Student> mix17 = new TreeSet<Student>(); Student[] st17 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[16].getSize(); i++ ){ int rN17 = rand17.nextInt(classes[16].getSize()); while ( mix17.contains(students[rN17]) ){//already chose rN17= rand17.nextInt(classes[16].getSize());//get another } mix17.add(students[rN17]); mix17.toArray(st17); st17 = mix17.toArray(st17); } for (int k = 0; k < classes[16].getSize() ; k++) { classes[16].addStudents(st17[k]); } System.out.println(classes[16].toString()); outFile.println(classes[16].toString()); Random rand18 = new Random(); Set<Student> mix18 = new TreeSet<Student>(); Student[] st18 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[17].getSize(); i++ ){ int rN18 = rand18.nextInt(classes[17].getSize()); while ( mix18.contains(students[rN18]) ){//already chose rN18= rand18.nextInt(classes[17].getSize());//get another } mix18.add(students[rN18]); mix18.toArray(st18); st18 = mix18.toArray(st18); } for (int k = 0; k < classes[17].getSize() ; k++) { classes[17].addStudents(st18[k]); } System.out.println(classes[17].toString()); outFile.println(classes[17].toString()); Random rand19 = new Random(); Set<Student> mix19 = new TreeSet<Student>(); Student[] st19 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[18].getSize(); i++ ){ int rN19 = rand19.nextInt(classes[18].getSize()); while ( mix19.contains(students[rN19]) ){//already chose rN19= rand19.nextInt(classes[18].getSize());//get another } mix19.add(students[rN19]); mix19.toArray(st19); st19 = mix19.toArray(st19); } for (int k = 0; k < classes[18].getSize() ; k++) { classes[18].addStudents(st19[k]); } System.out.println(classes[18].toString()); outFile.println(classes[18].toString()); Random rand20 = new Random(); Set<Student> mix20 = new TreeSet<Student>(); Student[] st20 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[19].getSize(); i++ ){ int rN20 = rand20.nextInt(classes[19].getSize()); while ( mix20.contains(students[rN20]) ){//already chose rN20= rand20.nextInt(classes[19].getSize());//get another } mix20.add(students[rN20]); mix20.toArray(st20); st20 = mix20.toArray(st20); } for (int k = 0; k < classes[19].getSize() ; k++) { classes[19].addStudents(st20[k]); } System.out.println(classes[19].toString()); outFile.println(classes[19].toString()); Random rand21 = new Random(); Set<Student> mix21 = new TreeSet<Student>(); Student[] st21 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[20].getSize(); i++ ){ int rN21 = rand21.nextInt(classes[20].getSize()); while ( mix21.contains(students[rN21]) ){//already chose rN21= rand21.nextInt(classes[20].getSize());//get another } mix21.add(students[rN21]); mix21.toArray(st21); st21 = mix21.toArray(st21); } for (int k = 0; k < classes[20].getSize() ; k++) { classes[20].addStudents(st21[k]); } System.out.println(classes[20].toString()); outFile.println(classes[20].toString()); Random rand22 = new Random(); Set<Student> mix22 = new TreeSet<Student>(); Student[] st22 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[21].getSize(); i++ ){ int rN22 = rand22.nextInt(classes[21].getSize()); while ( mix22.contains(students[rN22]) ){//already chose rN22= rand22.nextInt(classes[21].getSize());//get another } mix22.add(students[rN22]); mix22.toArray(st22); st22 = mix22.toArray(st22); } for (int k = 0; k < classes[21].getSize() ; k++) { classes[21].addStudents(st22[k]); } System.out.println(classes[21].toString()); outFile.println(classes[21].toString()); Random rand23 = new Random(); Set<Student> mix23 = new TreeSet<Student>(); Student[] st23 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[22].getSize(); i++ ){ int rN23 = rand23.nextInt(classes[22].getSize()); while ( mix23.contains(students[rN23]) ){//already chose rN23= rand23.nextInt(classes[22].getSize());//get another } mix23.add(students[rN23]); mix23.toArray(st23); st23 = mix23.toArray(st23); } for (int k = 0; k < classes[22].getSize() ; k++) { classes[22].addStudents(st23[k]); } System.out.println(classes[22].toString()); outFile.println(classes[22].toString()); Random rand24 = new Random(); Set<Student> mix24 = new TreeSet<Student>(); Student[] st24 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[23].getSize(); i++ ){ int rN24 = rand24.nextInt(classes[23].getSize()); while ( mix24.contains(students[rN24]) ){//already chose rN24= rand24.nextInt(classes[23].getSize());//get another } mix24.add(students[rN24]); mix24.toArray(st24); st24 = mix24.toArray(st24); } for (int k = 0; k < classes[23].getSize() ; k++) { classes[23].addStudents(st24[k]); } System.out.println(classes[23].toString()); outFile.println(classes[23].toString()); Random rand25 = new Random(); Set<Student> mix25 = new TreeSet<Student>(); Student[] st25 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[24].getSize(); i++ ){ int rN25 = rand25.nextInt(classes[24].getSize()); while ( mix25.contains(students[rN25]) ){//already chose rN25= rand25.nextInt(classes[24].getSize());//get another } mix25.add(students[rN25]); mix25.toArray(st25); st25 = mix25.toArray(st25); } for (int k = 0; k < classes[24].getSize() ; k++) { classes[24].addStudents(st25[k]); } System.out.println(classes[24].toString()); outFile.println(classes[24].toString()); Random rand26 = new Random(); Set<Student> mix26 = new TreeSet<Student>(); Student[] st26 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[25].getSize(); i++ ){ int rN26 = rand26.nextInt(classes[25].getSize()); while ( mix26.contains(students[rN26]) ){//already chose rN26= rand26.nextInt(classes[25].getSize());//get another } mix26.add(students[rN26]); mix26.toArray(st26); st26 = mix26.toArray(st26); } for (int k = 0; k < classes[25].getSize() ; k++) { classes[25].addStudents(st26[k]); } System.out.println(classes[25].toString()); outFile.println(classes[25].toString()); Random rand27 = new Random(); Set<Student> mix27 = new TreeSet<Student>(); Student[] st27 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[26].getSize(); i++ ){ int rN27 = rand27.nextInt(classes[26].getSize()); while ( mix27.contains(students[rN27]) ){//already chose rN27= rand27.nextInt(classes[26].getSize());//get another } mix27.add(students[rN27]); mix27.toArray(st27); st27 = mix27.toArray(st27); } for (int k = 0; k < classes[26].getSize() ; k++) { classes[26].addStudents(st27[k]); } System.out.println(classes[26].toString()); outFile.println(classes[26].toString()); Random rand28 = new Random(); Set<Student> mix28 = new TreeSet<Student>(); Student[] st28 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[27].getSize(); i++ ){ int rN28 = rand28.nextInt(classes[27].getSize()); while ( mix28.contains(students[rN28]) ){//already chose rN28= rand28.nextInt(classes[27].getSize());//get another } mix28.add(students[rN28]); mix28.toArray(st28); st28 = mix28.toArray(st28); } for (int k = 0; k < classes[27].getSize() ; k++) { classes[27].addStudents(st28[k]); } System.out.println(classes[27].toString()); outFile.println(classes[27].toString()); Random rand29 = new Random(); Set<Student> mix29 = new TreeSet<Student>(); Student[] st29 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[28].getSize(); i++ ){ int rN29 = rand29.nextInt(classes[28].getSize()); while ( mix29.contains(students[rN29]) ){//already chose rN29= rand29.nextInt(classes[28].getSize());//get another } mix29.add(students[rN29]); mix29.toArray(st29); st29 = mix29.toArray(st29); } for (int k = 0; k < classes[28].getSize() ; k++) { classes[28].addStudents(st29[k]); } System.out.println(classes[28].toString()); outFile.println(classes[28].toString()); Random rand30 = new Random(); Set<Student> mix30 = new TreeSet<Student>(); Student[] st30 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[29].getSize(); i++ ){ int rN30 = rand30.nextInt(classes[29].getSize()); while ( mix30.contains(students[rN30]) ){//already chose rN30= rand30.nextInt(classes[29].getSize());//get another } mix30.add(students[rN30]); mix30.toArray(st30); st30 = mix30.toArray(st30); } for (int k = 0; k < classes[29].getSize() ; k++) { classes[29].addStudents(st30[k]); } System.out.println(classes[29].toString()); outFile.println(classes[29].toString()); Random rand31 = new Random(); Set<Student> mix31 = new TreeSet<Student>(); Student[] st31 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[30].getSize(); i++ ){ int rN31 = rand31.nextInt(classes[30].getSize()); while ( mix31.contains(students[rN31]) ){//already chose rN31= rand31.nextInt(classes[30].getSize());//get another } mix31.add(students[rN31]); mix31.toArray(st31); st31 = mix31.toArray(st31); } for (int k = 0; k < classes[30].getSize() ; k++) { classes[30].addStudents(st31[k]); } System.out.println(classes[30].toString()); outFile.println(classes[30].toString()); Random rand32 = new Random(); Set<Student> mix32 = new TreeSet<Student>(); Student[] st32 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[31].getSize(); i++ ){ int rN32 = rand32.nextInt(classes[31].getSize()); while ( mix32.contains(students[rN32]) ){//already chose rN32= rand32.nextInt(classes[31].getSize());//get another } mix32.add(students[rN32]); mix32.toArray(st32); st32 = mix32.toArray(st32); } for (int k = 0; k < classes[31].getSize() ; k++) { classes[31].addStudents(st32[k]); } System.out.println(classes[31].toString()); outFile.println(classes[31].toString()); Random rand33 = new Random(); Set<Student> mix33 = new TreeSet<Student>(); Student[] st33 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[32].getSize(); i++ ){ int rN33 = rand33.nextInt(classes[32].getSize()); while ( mix33.contains(students[rN33]) ){//already chose rN33= rand33.nextInt(classes[32].getSize());//get another } mix33.add(students[rN33]); mix33.toArray(st33); st33 = mix33.toArray(st33); } for (int k = 0; k < classes[32].getSize() ; k++) { classes[32].addStudents(st33[k]); } System.out.println(classes[32].toString()); outFile.println(classes[32].toString()); Random rand34 = new Random(); Set<Student> mix34 = new TreeSet<Student>(); Student[] st34 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[33].getSize(); i++ ){ int rN34 = rand34.nextInt(classes[33].getSize()); while ( mix34.contains(students[rN34]) ){//already chose rN34= rand34.nextInt(classes[33].getSize());//get another } mix34.add(students[rN34]); mix34.toArray(st34); st34 = mix34.toArray(st34); } for (int k = 0; k < classes[33].getSize() ; k++) { classes[33].addStudents(st34[k]); } System.out.println(classes[33].toString()); outFile.println(classes[33].toString()); Random rand35 = new Random(); Set<Student> mix35 = new TreeSet<Student>(); Student[] st35 = new Student[classes[0].getSize()]; for ( int i = 0; i < classes[34].getSize(); i++ ){ int rN35 = rand35.nextInt(classes[34].getSize()); while ( mix35.contains(students[rN35]) ){//already chose rN35= rand35.nextInt(classes[34].getSize());//get another } mix35.add(students[rN35]); mix35.toArray(st35); st35 = mix35.toArray(st35); } for (int k = 0; k < classes[34].getSize() ; k++) { classes[34].addStudents(st35[k]); } System.out.println(classes[34].toString()); outFile.println(classes[34].toString()); outFile.close(); } public static void main(String[] args) throws FileNotFoundException { MainClass mainC = new MainClass(); } }
package DiscreteMathProject; /** * @author pradcoc * */ public class Student { private String name; private int numOfClasses; private ArrayList<Class> aList; private ArrayList<String> aList2; public Student(String name) { name = this.name; setName(name); } public String getName() { return name; } public void setName(String name2) { name = name2; } public void addClasses(Class c) { aList.add(c); } public String getClasses() { for (int i = 0; i < aList.size(); i++) { aList2.add(aList.get(i).getName()); } String str = aList2.toString(); return str; } public int getNumOfClasses() { numOfClasses = aList2.size(); return numOfClasses; } public String toString() { String str = "The student's name is: " + getName() + ". The student is in " + getNumOfClasses() + " classes. The classes are " + getClasses() + "."; return str; } }
package DiscreteMathProject; import java.util.ArrayList; import java.util.Random; /** * @author pradcoc * */ public class Class { private Student[] students; private String[] times; private String name; private String time; private int size; private Random r,r2; private Random[] random; private ArrayList<Student> aList; private ArrayList<String> aList2; public Class(String name) { name = this.name; times = new String[10]; times[0] = "8:00 a.m."; times[1] = "9:30 a.m."; times[2] = "11:00 a.m."; times[3] = "12:30 p.m."; times[4] = "2:00 p.m."; times[5] = "3:30 p.m."; times[6] = "5:00 p.m."; times[7] = "6:30 p.m."; times[8] = "8:00 p.m."; times[9] = "9:30 p.m."; aList = new ArrayList<Student>(); aList2 = new ArrayList<String>(); setName(name); } public String getTime() { r = new Random(); int x = r.nextInt(10); time= times[x]; return time; } public String getName() { return name; } public void setName(String name2) { name = name2; } public void addStudents(Student s) { aList.add(s); } public String getAdjacentClasses(Class[] classes) { ArrayList<String> penguinList = new ArrayList<String>(); for (int i = 0; i < classes.length; i++) { // how do I get it so that it checks the getArrayList2() method of each class and checks to see if // the get method, for any index, returns true, i.e., they have a Student in common // I'm baffled how to do it without it throwing some exception somewhere or making a glitch somewhere } } public ArrayList<Student> getArrayList() { return aList; } public int getSize() { r2 = new Random(); int x = r2.nextInt(26); if (x < 15) { x = 15; size = x; return size; } else { size = x; return size; } } public String toString() { String str = "The class: " + getName() + " is at " + getTime() + "and has " + getSize() + " students." + " The students in it are: " + getStudentsInClass() + "." ; return str; } public String getStudentsInClass() { for (int i = 0; i < getSize(); i++) { aList2.add(aList.get(i).getName()); } String str = aList2.toString(); return str; } public ArrayList<String> getStudentsInClass2() { return aList2; } }
For starters, what's causing the ArrayIndexOutOfBoundsException ?
http://www.javaprogrammingforums.com...m-class-3.html