help with java assignment

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

 HI guys, I need some help with java. I did most of the coding but stuck in dispalying the output graphically. I hope you guys can help me.  // Class Course// import java.util.*; public class Course { //Class Variables private int ID = -1; private String NAME = "NULL"; private int CREDITS = -1; private int ENROLLMENT_MIN = -1; private int ENROLLMENT_MAX = -1; private boolean GRADUATE = false; private ArrayList<Student> STUDENTS;   //ID Variable Methods public int getID() { return ID; }   public void setID(int id) { ID = id; }   //Name Methods public String getName() { return NAME; }   public void setName(String name) { NAME = name; }   //Credit Methods public int getCreditHours() { return CREDITS; }   public void setCreditHours(int credits) { CREDITS = credits; }   //Enrollment Methods public int getEnrollmentMin() { return ENROLLMENT_MIN; }   public void setEnrollmentMin(int min) { ENROLLMENT_MIN = min; }   public int getEnrollmentMax() { return ENROLLMENT_MAX; }   public void setEnrollmentMax(int max) { ENROLLMENT_MAX = max; }   //Graduate Methods public boolean isGraduateLevel() { return GRADUATE; }   public void setGraduateLevel(boolean graduate) { GRADUATE = graduate; }   //Validation Methods public boolean isValidStudent(Student student) { if(isGraduateLevel() != student.isGraduate()) return false; else if(getStudentCount() >= getEnrollmentMax()) return false; else if(isEnrolled(student)) return false; return true; }   public boolean isValidated() { for(int i = 0; i < getStudentCount(); i++) if(!isValidStudent(getStudent(i))) return false; return true; }   public boolean isEnrolled(Student student) { try { return getStudents().contains(student); } catch(Exception e) { return false; //No students exist } }   //Student Methods public ArrayList<Student> getStudents() { return STUDENTS; }   public Student getStudent(int index) { return STUDENTS.get(index); }   public void setStudents(ArrayList<Student> students) { STUDENTS = students; enrollStudents(); }   public void setStudent(int index, Student student) { STUDENTS.set(index, student); enrollStudents(); }   public void addStudent(Student student) { try { STUDENTS.add(student); } catch(Exception e) { Student[] temp = {student}; //Create a singular array List<Student> list = Arrays.asList(temp); //Convert it to a list setStudents(new ArrayList<Student>(list)); //Set it as the students } //enrollStudents(); }   //Counting Methods public int getStudentCount() { try { return STUDENTS.size(); } catch(Exception e) { return 0; //No students exist } }   //Searching Methods public Student findStudentByID(int id) { for(int i = 0; i < getStudentCount(); i++) if(getStudent(i).getID() == id) return getStudent(i); return null; }   public Student findStudentByName(String name) { for(int i = 0; i < getStudentCount(); i++) if(getStudent(i).getName().compareTo(name) == 0) return getStudent(i); return null; }   //Other Methods public String toString() { //Outputs in the format: // Name ID \t // [Graduate] (T/F) Min Max \t // [IDs] (1, 2, 3, 4...)   String output = ""; output += getName() + " " + getID() + "\t"; output += isGraduateLevel() + " " + getEnrollmentMin() + " " + getEnrollmentMax();   for(int i = 0; i < getStudentCount()-1; i++) output += getStudent(i).getID() + ", "; output += getStudent(getStudentCount()-1).getID();   return output; }   public int compareTo(Course course) { if(getID() > course.getID()) return 1; else if(getID() < course.getID()) return -1; else return 0; }   private void enrollStudents() { for(int i = 0; i < getStudentCount(); i++) if(!getStudent(i).isEnrolled(this)) getStudent(i).addCourse(this); } }       Last edited: 30-Nov-11 10:05 AM

iamunknown · Nov 30, 2011 10:04 AM · 5,950 views

7 Replies

      import java.util.*;   public class Roster { //Class Variables private ArrayList<Course> COURSES; private ArrayList<Student> STUDENTS;   //Course Methods public ArrayList<Course> getCourses() { return COURSES; }   public Course getCourse(int index) { try { return COURSES.get(index); } catch(Exception e) { System.out.println("Roster - getCourse(int index)\n\tUnable to call index: " + index + "\n"); return null; } }   public void setCourses(ArrayList<Course> courses) { COURSES = courses; updateStudents(); }   public void setCourse(int index, Course course) { COURSES.set(index, course); updateStudents(); }   public void addCourse(Course course) { COURSES.add(course); updateStudents(); }   //Student Methods private void updateStudents() { //ArrayList needs to be initialized with something try { ArrayList<Student> students = getCourse(0).getStudents();   //Add in the students from all of the courses, starting at one for(int i = 1; i < getCourseCount(); i++) for(int k = 0; k < getCourse(i).getStudentCount(); k++) students.add(getCourse(i).getStudent(k)); //Remove the duplicates for(int i = 0; i < students.size(); i++) while(students.lastIndexOf(students.get(i)) != i) students.remove(students.lastIndexOf(students.get(i)));   students.trimToSize(); STUDENTS = students; } catch(Exception e) { //Null pointer in case of no courses existing System.out.println("Roster - updateStudents()\n\tUnable to create student list\n"); return; } }   public ArrayList<Student> getStudents() { updateStudents(); return STUDENTS; }   public Student getStudent(int index) { updateStudents(); try { return STUDENTS.get(index); } catch(Exception e) { System.out.println("Roster - getStudent(int index)\n\tUnable to call index: " + index + "\n"); return null; } }   //Counting Methods public int getCourseCount() { try { return COURSES.size(); } catch(Exception e) { return 0; //No courses exist } }   public int getGraduateCourseCount() { int count = 0; for(int i = 0; i < getCourseCount(); i++) if(getCourse(i).isGraduateLevel()) count++; return count; }   public int getUndergraduateCourseCount() { return getCourseCount() - getGraduateCourseCount(); }   public int getStudentCount() { try { updateStudents(); return getStudents().size(); } catch(Exception e) { return 0; //No students exist } }   public int getGraduateStudentCount() { int count = 0; for(int i = 0; i < getStudentCount(); i++) if(getStudent(i).isGraduate()) count++; return count; }   public int getUndergraduateStudentCount() { return getStudentCount() - getGraduateStudentCount(); }   //Searching Methods public Course findCourseByID(int id) { for(int i = 0; i < getCourseCount(); i++) if(getCourse(i).getID() == id) return getCourse(i); return null; }   public Course findCourseByName(String name) { for(int i = 0; i < getCourseCount(); i++) if(getCourse(i).getName().compareTo(name) == 0) return getCourse(i); return null; }   public Student findStudentByID(int id) { updateStudents(); for(int i = 0; i < getStudentCount(); i++) if(getStudent(i).getID() == id) return getStudent(i); return null; }   public Student findStudentByName(String name) { updateStudents(); for(int i = 0; i < getStudentCount(); i++) if(getStudent(i).getName().compareTo(name) == 0) return getStudent(i); return null; }   //Validation Methods public ArrayList<Student> findAvailableStudents(Course course) { ArrayList<Student> results = getStudents(); int size = getStudentCount(); for(int i = 0; i < size; i++) if(course.isValidStudent(results.get(i))) { results.remove(i); i--; size--; } results.trimToSize(); return results; }   public ArrayList<Course> findAvailableCourses(Student student) { ArrayList<Course> results = getCourses(); int size = getCourseCount(); for(int i = 0; i < size; i++) if(student.isValidCourse(results.get(i))) { results.remove(i); i--; size--; } results.trimToSize(); return results; }   //Other Methods public String toString() { updateStudents(); String output = "";   for(int i = 0; i < getStudentCount(); i++) output += getStudent(i).toString() + "\n"; for(int i = 0; i < getCourseCount(); i++) output += getCourse(i).toString() + "\n"; return output; } }

iamunknown · Nov 30, 2011 10:06 AM

  import java.util.*;   public class Student { //Class Variables private int ID = -1; private String FIRST_NAME = "NULL"; private String MIDDLE_NAME = "NULL"; private String LAST_NAME = "NULL"; private String ADDRESS = "NULL"; private boolean REGISTERED = false; private boolean GRADUATE = false; private ArrayList<Course> COURSES;   //ID Methods public int getID() { return ID; }   public void setID(int id) { ID = id; }   //Name Methods public String getName() { if(MIDDLE_NAME.equals("NULL")) return FIRST_NAME + " " + LAST_NAME; return FIRST_NAME + " " + MIDDLE_NAME + " " + LAST_NAME; }   public void setName(String name) { if(name.indexOf(" ") > 0) { if(name.indexOf(" ", name.indexOf(" ")+1) > 0) { setFirstName(name.substring(0, name.indexOf(" "))); setMiddleName(name.substring(name.indexOf(" ")+1, name.indexOf(" ", name.indexOf(" ")+1))); setLastName(name.substring(name.indexOf(" ", name.indexOf(" ")+1))); } else { setFirstName(name.substring(0, name.indexOf(" "))); setLastName(name.substring(name.indexOf(" ")+1)); } } else setFirstName(name); }   //First Name Methods public String getFirstName() { return FIRST_NAME; }   public void setFirstName(String first) { FIRST_NAME = first; }   //Middle Name Methods public String getMiddleName() { return MIDDLE_NAME; }   public void setMiddleName(String middle) { MIDDLE_NAME = middle; }   public String getMI() { return getMiddleName().charAt(0) + "."; }   //Last Name Methods public String getLastName() { return LAST_NAME; }   public void setLastName(String last) { LAST_NAME = last; }   //Address Methods public String getAddress() { return ADDRESS; }   public void setAddress(String address) { ADDRESS = address; }   //Registered Methods public boolean isRegistered() { return REGISTERED; }   public void setRegistered(boolean registered) { REGISTERED = registered; }   //Graduate Methods public boolean isGraduate() { return GRADUATE; }   public void setGraduate(boolean graduate) { GRADUATE = graduate; }   //Course Variables public ArrayList<Course> getCourses() { return COURSES; }   public Course getCourse(int index) { return COURSES.get(index); }   public void setCourses(ArrayList<Course> courses) { COURSES = courses; }   public void setCourse(int index, Course course) { COURSES.set(index, course); }   public void addCourse(Course course) { try { COURSES.add(course); } catch(Exception e) { Course[] temp = {course}; //Create a singular array List<Course> list = Arrays.asList(temp); //Convert it to a list setCourses(new ArrayList<Course>(list)); //Set it as the courses } }   //Counting Methods public int getCourseCount() { try { return COURSES.size(); } catch(Exception e) { return 0; //No courses exist } }   public int getCreditHours() { int sum = 0; for(int i = 0; i < getCourseCount(); i++) sum += getCourse(i).getCreditHours(); return sum; }   public int getCreditLimit() { return isGraduate() ? 12 : 6; //These values are specified by the assignment }   //Validation Methods public boolean isValidCourse(Course course) { //Requires proper graduate level and credit count if(isGraduate() != course.isGraduateLevel()) return false; else if(getCreditHours() + course.getCreditHours() > getCreditLimit()) return false; else if(isEnrolled(course)) return false; return true; }   public boolean isValidated() { for(int i = 0; i < getCourseCount(); i++) if(!isValidCourse(getCourse(i))) return false; return true; }   public boolean isEnrolled(Course course) { try { return getCourses().contains(course); } catch(Exception e) { return false; //No courses exist } }   //Searching Methods public Course findCourseByID(int id) { for(int i = 0; i < getCourseCount(); i++) if(getCourse(i).getID() == id) return getCourse(i); return null; }   public Course findCourseByName(String name) { for(int i = 0; i < getCourseCount(); i++) if(getCourse(i).getName().compareTo(name) == 0) return getCourse(i); return null; }   //Other Methods public String toString() { //Outputs in the format: // Name ID \t // Address \t // [Graduate] [Registered] (T/F) \t // [IDs] (1, 2, 3, 4...)   String output = ""; output += getName() + " " + getID() + "\t"; output += getAddress() + "\t"; output += isGraduate() + " " + isRegistered() + "\t";   for(int i = 0; i < getCourseCount()-1; i++) output += getCourse(i).getID() + ", "; output += getCourse(getCourseCount()-1).getID();   return output; }   public int compareTo(Student student) { return getLastName().compareTo(student.getLastName()); } }

iamunknown · Nov 30, 2011 10:06 AM

&nbsp; &nbsp; import java.util.*; import java.lang.StrictMath; &nbsp; public class Generator { Random generator = new Random(); &nbsp; //Roster Components public Roster getRoster() { Roster roster = new Roster(); &nbsp; ArrayList&lt;Student&gt; students = new ArrayList&lt;Student&gt;(); ArrayList&lt;Course&gt; courses = new ArrayList&lt;Course&gt;(); &nbsp; //Generate data for(int i = 0; i &lt; 100; i++) students.add(getStudent()); for(int i = 0; i &lt; 20; i++) courses.add(getCourse()); &nbsp; roster.setCourses(courses); //Add in the courses &nbsp; for(int i = 0; i &lt; roster.getCourseCount(); i++) //Loop through the courses { int base = roster.getCourse(i).getEnrollmentMin(); int ceil = roster.getCourse(i).getEnrollmentMax()-base; &nbsp; //Create an array between the min and max enrollment sizes Student[] temp = new Student[generator.nextInt(ceil)+base]; &nbsp; for(int k = 0; k &lt; temp.length;) { Student student = students.get(generator.nextInt(students.size())); //Grab a random student if(roster.getCourse(i).isValidStudent(student)) //See if the student can be added temp[k++] = student; //Add the student } &nbsp; roster.getCourse(i).setStudents(new ArrayList&lt;Student&gt;(Arrays.asList(temp))); } &nbsp; return roster; } &nbsp; //Student Components public Student getStudent() { Student student = new Student(); student.setID(getStudentID(4)); student.setName(getStudentName()); student.setAddress(getStudentAddress()); student.setGraduate(getStudentGraduate()); return student; } &nbsp; public int getStudentID(int length) { //10^length gives me a number starting with one with 'n'-1 remaining 0's //To create a base amount, I add this number to whatever the random number would be //To stay within the length, I create a number with an extra 0 at the end, and subtract 1, giving me 'n' number of 9's //I then subtract the base amount from this number to create my random range of (10000...n to 99999....n) &nbsp; int base = (int)Math.pow(10,length); int ceiling = (int)Math.pow(10,length+1)-1; &nbsp; return generator.nextInt(ceiling-base)+base; } &nbsp; public String getStudentName() { return getStudentFirstName() + &quot; &quot; + getStudentMiddleName() + &quot; &quot; + getStudentLastName(); } &nbsp; public String getStudentFirstName() { String[] first = {&quot;Mohammed&quot;, &quot;Ahmed&quot;, &quot;Ali&quot;, &quot;Ibrahim&quot;, &quot;Abdallah&quot;, &quot;Khaled&quot;, &quot;Sarah&quot;, &quot;Mona&quot;, &quot;Omar&quot;, &quot;Yousef&quot;, //10 &quot;Adam&quot;, &quot;David&quot;, &quot;Eric&quot;, &quot;Arthur&quot;, &quot;Tobias&quot;, &quot;Alexander&quot;, &quot;Simon&quot;, &quot;Jonas&quot;, &quot;Sebastian&quot;, &quot;Felix&quot;, //20 &quot;Julian&quot;, &quot;Ivan&quot;, &quot;Nathan&quot;, &quot;Lucas&quot;, &quot;Thomas&quot;, &quot;Louis&quot;, &quot;Noah&quot;, &quot;Hugo&quot;, &quot;Tom&quot;, &quot;Gabriel&quot;, //30 &quot;Daniel&quot;, &quot;Antonio&quot;, &quot;Dominik&quot;, &quot;Leon&quot;, &quot;Oscar&quot;,&quot;Peter&quot;, &quot;Michael&quot;, &quot;Jack&quot;, &quot;Harry&quot;, &quot;Charlie&quot;, //40 &quot;William&quot;, &quot;Joshua&quot;, &quot;George&quot;, &quot;James&quot;, &quot;Leo&quot;, &quot;Robin&quot;, &quot;Mathis&quot;, &quot;Ethan&quot;, &quot;Raphael&quot;, &quot;Paul&quot;, //50 &quot;Felix&quot;, &quot;Ben&quot;, &quot;Francesco&quot;, &quot;Leonardo&quot;, &quot;Nicola&quot;, &quot;Gustav&quot;, &quot;Robert&quot;, &quot;Ryan&quot;, &quot;Marian&quot;, &quot;Sergey&quot;, //60 &quot;Dimitry&quot;, &quot;Ivan&quot;, &quot;Lewis&quot;, &quot;Logan&quot;, &quot;Aaron&quot;, &quot;Oliver&quot;, &quot;Jamie&quot;, &quot;Cameron&quot;, &quot;Patrick&quot;, &quot;Diego&quot;, //70 &quot;Mario&quot;, &quot;Alejandro&quot;, &quot;Pablo&quot;, &quot;Mary&quot;, &quot;Eva&quot;, &quot;Anna&quot;, &quot;Hannah&quot;, &quot;Sophie&quot;, &quot;Julia&quot;, &quot;Laura&quot;, //80 &quot;Marie&quot;, &quot;Alexandra&quot;, &quot;Louise&quot;, &quot;Clara&quot;, &quot;Emma&quot;, &quot;Ella&quot;, &quot;Elise&quot;, &quot;Camille&quot;, &quot;Yasmine&quot;, &quot;Sara&quot;, //90 &quot;Gabriela&quot;, &quot;Isabella&quot;, &quot;Rebecca&quot;, &quot;Lily&quot;, &quot;Emily&quot;, &quot;Amelia&quot;, &quot;Jessica&quot;, &quot;Ruby&quot;, &quot;Chloe&quot;, &quot;Grace&quot;, //100 &quot;Daisy&quot;, &quot;Alice&quot;, &quot;Olivia&quot;, &quot;Greta&quot;, &quot;Viola&quot;, &quot;Lisa&quot;, &quot;Venessa&quot;, &quot;Lea&quot;, &quot;Lucy&quot;, &quot;Katie&quot;, //110 &quot;Katrina&quot;, &quot;Diana&quot;, &quot;Victoria&quot;, &quot;Pedro&quot;, &quot;Mateo&quot;, &quot;Luiz&quot;, &quot;Benjamin&quot;, &quot;Carter&quot;, &quot;Jacob&quot;, &quot;Mathew&quot;, //120 &quot;Alexis&quot;, &quot;Justin&quot;, &quot;Christopher&quot;, &quot;Anthony&quot;, &quot;Ashley&quot;, &quot;Margaret&quot;, &quot;Dorothy&quot;, &quot;Elizabeth&quot;, &quot;Linda&quot;, &quot;Mary&quot;, //130 &quot;Madison&quot;, &quot;Patricia&quot;, &quot;Barbara&quot;, &quot;Susan&quot;, &quot;Dorothy&quot;, &quot;Kayla&quot;, &quot;Vivian&quot;, &quot;Nicole&quot;, &quot;Destiny&quot;, &quot;Sophia&quot;, //140 &quot;Cooper&quot;, &quot;Jackson&quot;, &quot;Riley&quot;, &quot;Ethan&quot;, &quot;Max&quot;, &quot;Tyler&quot;, &quot;Austin&quot;, &quot;Chad&quot;, &quot;Christian&quot;, &quot;Lloyd&quot;, //150 &quot;Summer&quot;, &quot;Charlotte&quot;, &quot;Angelica&quot;, &quot;Angela&quot;, &quot;Jasmine&quot;, &quot;Kimberly&quot;, &quot;Angel&quot;, &quot;Jared&quot;, &quot;Jonathon&quot;, &quot;Nikki&quot;}; //160 &nbsp; return first[generator.nextInt(first.length)]; } &nbsp; public String getStudentMiddleName() { String[] middle = {&quot;Mohammed&quot;, &quot;Ahmed&quot;, &quot;Ali&quot;, &quot;Ibrahim&quot;, &quot;Abdallah&quot;, &quot;Khaled&quot;, &quot;Sarah&quot;, &quot;Mona&quot;, &quot;Omar&quot;, &quot;Yousef&quot;, //10 &quot;Adam&quot;, &quot;David&quot;, &quot;Eric&quot;, &quot;Arthur&quot;, &quot;Tobias&quot;, &quot;Alexander&quot;, &quot;Simon&quot;, &quot;Jonas&quot;, &quot;Sebastian&quot;, &quot;Felix&quot;, //20 &quot;Julian&quot;, &quot;Ivan&quot;, &quot;Nathan&quot;, &quot;Lucas&quot;, &quot;Thomas&quot;, &quot;Louis&quot;, &quot;Noah&quot;, &quot;Hugo&quot;, &quot;Tom&quot;, &quot;Gabriel&quot;, //30 &quot;Daniel&quot;, &quot;Antonio&quot;, &quot;Dominik&quot;, &quot;Leon&quot;, &quot;Oscar&quot;,&quot;Peter&quot;, &quot;Michael&quot;, &quot;Jack&quot;, &quot;Harry&quot;, &quot;Charlie&quot;, //40 &quot;William&quot;, &quot;Joshua&quot;, &quot;George&quot;, &quot;James&quot;, &quot;Leo&quot;, &quot;Robin&quot;, &quot;Mathis&quot;, &quot;Ethan&quot;, &quot;Raphael&quot;, &quot;Paul&quot;, //50 &quot;Felix&quot;, &quot;Ben&quot;, &quot;Francesco&quot;, &quot;Leonardo&quot;, &quot;Nicola&quot;, &quot;Gustav&quot;, &quot;Robert&quot;, &quot;Ryan&quot;, &quot;Marian&quot;, &quot;Sergey&quot;, //60 &quot;Dimitry&quot;, &quot;Ivan&quot;, &quot;Lewis&quot;, &quot;Logan&quot;, &quot;Aaron&quot;, &quot;Oliver&quot;, &quot;Jamie&quot;, &quot;Cameron&quot;, &quot;Patrick&quot;, &quot;Diego&quot;, //70 &quot;Mario&quot;, &quot;Alejandro&quot;, &quot;Pablo&quot;, &quot;Mary&quot;, &quot;Eva&quot;, &quot;Anna&quot;, &quot;Hannah&quot;, &quot;Sophie&quot;, &quot;Julia&quot;, &quot;Laura&quot;, //80 &quot;Marie&quot;, &quot;Alexandra&quot;, &quot;Louise&quot;, &quot;Clara&quot;, &quot;Emma&quot;, &quot;Ella&quot;, &quot;Elise&quot;, &quot;Camille&quot;, &quot;Yasmine&quot;, &quot;Sara&quot;, //90 &quot;Gabriela&quot;, &quot;Isabella&quot;, &quot;Rebecca&quot;, &quot;Lily&quot;, &quot;Emily&quot;, &quot;Amelia&quot;, &quot;Jessica&quot;, &quot;Ruby&quot;, &quot;Chloe&quot;, &quot;Grace&quot;, //100 &quot;Daisy&quot;, &quot;Alice&quot;, &quot;Olivia&quot;, &quot;Greta&quot;, &quot;Viola&quot;, &quot;Lisa&quot;, &quot;Venessa&quot;, &quot;Lea&quot;, &quot;Lucy&quot;, &quot;Katie&quot;, //110 &quot;Katrina&quot;, &quot;Diana&quot;, &quot;Victoria&quot;, &quot;Pedro&quot;, &quot;Mateo&quot;, &quot;Luiz&quot;, &quot;Benjamin&quot;, &quot;Carter&quot;, &quot;Jacob&quot;, &quot;Mathew&quot;, //120 &quot;Alexis&quot;, &quot;Justin&quot;, &quot;Christopher&quot;, &quot;Anthony&quot;, &quot;Ashley&quot;, &quot;Margaret&quot;, &quot;Dorothy&quot;, &quot;Elizabeth&quot;, &quot;Linda&quot;, &quot;Mary&quot;, //130 &quot;Madison&quot;, &quot;Patricia&quot;, &quot;Barbara&quot;, &quot;Susan&quot;, &quot;Dorothy&quot;, &quot;Kayla&quot;, &quot;Vivian&quot;, &quot;Nicole&quot;, &quot;Destiny&quot;, &quot;Sophia&quot;, //140 &quot;Cooper&quot;, &quot;Jackson&quot;, &quot;Riley&quot;, &quot;Ethan&quot;, &quot;Max&quot;, &quot;Tyler&quot;, &quot;Austin&quot;, &quot;Chad&quot;, &quot;Christian&quot;, &quot;Lloyd&quot;, //150 &quot;Summer&quot;, &quot;Charlotte&quot;, &quot;Angelica&quot;, &quot;Angela&quot;, &quot;Jasmine&quot;, &quot;Kimberly&quot;, &quot;Angel&quot;, &quot;Jared&quot;, &quot;Jonathon&quot;, &quot;Nikki&quot;}; //160 &nbsp; return middle[generator.nextInt(middle.length)]; } &nbsp; public String getStudentLastName() { String[] last = {&quot;Smith&quot;, &quot;Johnson&quot;, &quot;Williams&quot;, &quot;Brown&quot;, &quot;Jones&quot;, &quot;Miller&quot;, &quot;Davis&quot;, &quot;Garcia&quot;, &quot;Rodriguez&quot;, &quot;Wilson&quot;, //10 &quot;Martinez&quot;, &quot;Anderson&quot;, &quot;Taylor&quot;, &quot;Thomas&quot;, &quot;Hernandez&quot;, &quot;Moore&quot;, &quot;Martin&quot;, &quot;Jackson&quot;, &quot;Thompson&quot;, &quot;White&quot;, //20 &quot;Lopez&quot;, &quot;Lee&quot;, &quot;Gonzalez&quot;, &quot;Harris&quot;, &quot;Clark&quot;, &quot;Lewis&quot;, &quot;Robinson&quot;, &quot;Walker&quot;, &quot;Perez&quot;, &quot;Hall&quot;, //30 &quot;Young&quot;, &quot;Allen&quot;, &quot;Sanchez&quot;, &quot;Wright&quot;, &quot;King&quot;, &quot;Scott&quot;, &quot;Green&quot;, &quot;Baker&quot;, &quot;Adams&quot;, &quot;Nelson&quot;, //40 &quot;Hill&quot;, &quot;Ramirez&quot;, &quot;Campbell&quot;, &quot;Mitchell&quot;, &quot;Roberts&quot;, &quot;Carter&quot;, &quot;Phillips&quot;, &quot;Evans&quot;, &quot;Turner&quot;, &quot;Parker&quot;, //50 &quot;Collins&quot;, &quot;Edwards&quot;, &quot;Stewart&quot;, &quot;Flores&quot;, &quot;Morris&quot;, &quot;Nguyen&quot;, &quot;Murphy&quot;, &quot;Rivera&quot;, &quot;Cook&quot;, &quot;Rogers&quot;, //60 &quot;Morgan&quot;, &quot;Peterson&quot;, &quot;Cooper&quot;, &quot;Reed&quot;, &quot;Bailey&quot;, &quot;Bell&quot;, &quot;Gomez&quot;, &quot;Kelly&quot;, &quot;Howard&quot;, &quot;Ward&quot;, //70 &quot;Cox&quot;, &quot;Diaz&quot;, &quot;Richardson&quot;, &quot;Wood&quot;, &quot;Watson&quot;, &quot;Brooks&quot;, &quot;Bennett&quot;, &quot;Gray&quot;, &quot;James&quot;, &quot;Reyes&quot;, //80 &quot;Cruz&quot;, &quot;Hughes&quot;, &quot;Price&quot;, &quot;Myers&quot;, &quot;Long&quot;, &quot;Foster&quot;, &quot;Sanders&quot;, &quot;Ross&quot;, &quot;Morales&quot;, &quot;Powell&quot;, //90 &quot;Sullivan&quot;, &quot;Russel&quot; ,&quot;Ortiz&quot;, &quot;Jenkins&quot;, &quot;Gutierrez&quot;, &quot;Perry&quot;, &quot;Butler&quot;, &quot;Barnes&quot;, &quot;Fisher&quot;, &quot;Henderson&quot;, //100 &quot;Coleman&quot;, &quot;Simmons&quot;, &quot;Patterson&quot;, &quot;Jordan&quot;, &quot;Reynolds&quot;, &quot;Hamilton&quot;, &quot;Graham&quot;, &quot;Kim&quot;, &quot;Gonzales&quot;, &quot;Alexander&quot;, //110 &quot;Ramos&quot;, &quot;Wallace&quot;, &quot;Griffin&quot;, &quot;West&quot;, &quot;Cole&quot;, &quot;Hayes&quot;, &quot;Chaves&quot;, &quot;Gibson&quot;, &quot;Bryant&quot;, &quot;Ellis&quot;, //120 &quot;Stevens&quot;, &quot;Murray&quot;, &quot;Ford&quot;, &quot;Marshall&quot;, &quot;Owens&quot;, &quot;McDonald&quot;, &quot;Harrison&quot;, &quot;Ruiz&quot;, &quot;Kennedy&quot;, &quot;Wells&quot;, //130 &quot;Alvarez&quot;, &quot;Woods&quot;, &quot;Mendoza&quot;, &quot;Castillo&quot;, &quot;Olson&quot;, &quot;Webb&quot;, &quot;Washington&quot;, &quot;Tucker&quot;, &quot;Freeman&quot;, &quot;Burns&quot;, //140 &quot;Henry&quot;, &quot;Vasquez&quot;, &quot;Snyder&quot;, &quot;Simpson&quot;, &quot;Crawford&quot;, &quot;Jimenez&quot;, &quot;Porter&quot;, &quot;Mason&quot;, &quot;Shaw&quot;, &quot;Gordon&quot;, //150 &quot;Wagner&quot;, &quot;Hunter&quot;, &quot;Romero&quot;, &quot;Hicks&quot;, &quot;Dixon&quot;, &quot;Hunt&quot;, &quot;Palmer&quot;, &quot;Robertson&quot;, &quot;Black&quot;, &quot;Holmes&quot;}; //160 &nbsp; return last[generator.nextInt(last.length)]; } &nbsp; public String getStudentAddress() { String[] direction = {&quot;&quot;, &quot; North&quot;, &quot;&quot; , &quot; East&quot;, &quot;&quot;, &quot; South&quot;, &quot;&quot;, &quot; West&quot;}; //8 (5) &nbsp; String[] street = {&quot;Main&quot;, &quot;Church&quot;, &quot;High&quot;, &quot;Elm&quot;, &quot;Chestnut&quot;, &quot;Maple&quot;, &quot;Center&quot;, &quot;Broad&quot;, &quot;Washington&quot;, &quot;Walnut&quot;, //10 &quot;1st&quot;, &quot;2nd&quot;, &quot;3rd&quot;, &quot;4th&quot;, &quot;5th&quot;, &quot;Pine&quot;, &quot;Water&quot;, &quot;Park&quot;, &quot;School&quot;, &quot;Union&quot;, //20 &quot;Oak&quot;, &quot;River&quot;, &quot;Prospect&quot;, &quot;Spring&quot;, &quot;Market&quot;, &quot;Court&quot;, &quot;Front&quot;, &quot;Highland&quot;, &quot;Cedar&quot;, &quot;Spruce&quot;, //30 &quot;Central&quot;, &quot;Cherry&quot;, &quot;State&quot;, &quot;Bridge&quot;, &quot;Franklin&quot;, &quot;Ridge&quot;, &quot;Lincoln&quot;, &quot;Locust&quot;, &quot;Pleasant&quot;, &quot;Adams&quot;, //40 &quot;Dogwood&quot;, &quot;Mill&quot;, &quot;Liberty&quot;, &quot;Green&quot;, &quot;Grove&quot;, &quot;Hill&quot;, &quot;Hillside&quot;, &quot;Broadway&quot;, &quot;Elizabeth&quot;, &quot;Jefferson&quot;, //50 &quot;Academy&quot;, &quot;Hickory&quot;, &quot;Holly&quot;, &quot;Jackson&quot;, &quot;Meadow&quot;, &quot;Pearl&quot;, &quot;Vine&quot;, &quot;Arch&quot;, &quot;New&quot;, &quot;Valley&quot;}; //60 &nbsp; String[] annex = {&quot;Road&quot;, &quot;Street&quot;, &quot;Boulevard&quot;, &quot;Lane&quot;, &quot;Avenue&quot;, &quot;Parkway&quot;, &quot;Court&quot;, &quot;Drive&quot;}; //8 &nbsp; return getStudentID(3) + &quot; &quot; + direction[generator.nextInt(direction.length)] + &quot; &quot; + street[generator.nextInt(street.length)] + &quot; &quot; + annex[generator.nextInt(annex.length)]; } &nbsp; public boolean getStudentGraduate() { return generator.nextBoolean(); } &nbsp; //Course Components public Course getCourse() { Course course = new Course(); course.setID(getCourseID()); course.setName(getCourseName()); course.setCreditHours(getCourseCreditHours(course)); course.setEnrollmentMin(getCourseEnrollmentMin()); course.setEnrollmentMax(getCourseEnrollmentMax()); course.setGraduateLevel(getCourseGraduateLevel(course)); &nbsp; return course; } &nbsp; public int getCourseID() { return (generator.nextInt(7)+1)*1000 + (generator.nextInt(5)+1)*100 + generator.nextInt(3)*10 + generator.nextInt(3); } &nbsp; public String getCourseName() { String[] name = {&quot;AP&quot;, &quot;ARTS&quot;, &quot;ATEC&quot;, &quot;BA&quot;, &quot;BIOL&quot;, &quot;BIS&quot;, &quot;BMEN&quot;, &quot;CE&quot;, &quot;CGS&quot;, &quot;CHEM&quot;, //10 &quot;CRIM&quot;, &quot;CRWT&quot;, &quot;CS&quot;, &quot;DANC&quot;, &quot;DMTH&quot;, &quot;DRAM&quot;, &quot;ECON&quot;, &quot;ECS&quot;, &quot;ECSC&quot;, &quot;ED&quot;, //20 &quot;EE&quot;, &quot;EMTH&quot;, &quot;ENGR&quot;, &quot;FILM&quot;, &quot;FIN&quot;, &quot;GEOG&quot;, &quot;GEOS&quot;, &quot;GOVT&quot;, &quot;HIST&quot;, &quot;MATH&quot;, //30 &quot;MECH&quot;, &quot;MILS&quot;, &quot;MUSI&quot;, &quot;NANO&quot;, &quot;NSC&quot;, &quot;PHIL&quot;, &quot;PHYS&quot;, &quot;PSCI&quot; ,&quot;PSY&quot;, &quot;RHET&quot;, //40 &quot;SCE&quot;, &quot;SCI&quot;, &quot;SE&quot;, &quot;SOC&quot;, &quot;STAT&quot;, &quot;SYSM&quot;, &quot;TE&quot;, &quot;UNIV&quot;}; //48 &nbsp; return name[generator.nextInt(name.length)]; } &nbsp; public int getCourseCreditHours(Course course) { try <span

iamunknown · Nov 30, 2011 10:07 AM

Continued from Roster class. &nbsp; { return Integer.parseInt((course.getID()+&quot;&quot;).charAt(1)+&quot;&quot;); } catch(Exception e) { return -1; } } &nbsp; public int getCourseEnrollmentMin() { int[] min = {5,7,10}; //3 return min[generator.nextInt(min.length)]; } &nbsp; public int getCourseEnrollmentMax() { int[] max = {15, 20, 25, 30, 35, 40, 45, 50, 55, 60}; //11 return max[generator.nextInt(max.length)]; } &nbsp; public boolean getCourseGraduateLevel(Course course) { return (Integer.parseInt((course.getID()+&quot;&quot;).charAt(0)+&quot;&quot;)) &gt; 4; } } //Class Main// import java.util.*; &nbsp; public class Main { public static void main(String[] args) { Generator generator = new Generator(); Roster roster = generator.getRoster(); &nbsp; String output = &quot;COURSE LIST\n\n&quot;; for(int i = 0; i &lt; roster.getCourseCount(); i++) { output += &quot;ID: &quot; + roster.getCourse(i).getID() + &quot;\n&quot;; output += &quot;Name: &quot; + roster.getCourse(i).getName() + &quot;\n&quot;; output += &quot;Graduate Level: &quot; + (roster.getCourse(i).isGraduateLevel() ? &quot;Yes&quot; : &quot;No&quot;) + &quot;\n&quot;; output += &quot;Credit Hours: &quot; + roster.getCourse(i).getCreditHours() + &quot;\n&quot;; output += &quot;Enrollment Boundary: &quot; + roster.getCourse(i).getEnrollmentMin() + &quot; to &quot; + roster.getCourse(i).getEnrollmentMax() + &quot;\n&quot;; output += &quot;Student List: &quot;; &nbsp; for(int k = 0; k &lt; roster.getCourse(i).getStudentCount(); k++) output += roster.getCourse(i).getStudent(k).getID() + &quot; &quot;; output += &quot;\n&quot;; &nbsp; output += &quot;\n&quot;; } &nbsp; output += &quot;STUDENT LIST\n\n&quot;; &nbsp; for(int i = 0; i &lt; roster.getStudentCount(); i++) { output += &quot;ID: &quot; + roster.getStudent(i).getID() + &quot;\n&quot;; output += &quot;Name: &quot; + roster.getStudent(i).getName() + &quot;\n&quot;; output += &quot;Address: &quot; + roster.getStudent(i).getAddress() + &quot;\n&quot;; output += &quot;Graduate: &quot; + (roster.getStudent(i).isGraduate() ? &quot;Yes&quot; : &quot;No&quot;) + &quot;\n&quot;; output += &quot;Course List: &quot;; &nbsp; for(int k = 0; k &lt; roster.getStudent(i).getCourseCount(); k++) output += roster.getStudent(i).getCourse(k).getID() + &quot; &quot;; output += &quot;\n&quot;; &nbsp; output += &quot;\n&quot;; } &nbsp; GUI.create(&quot;School Roster&quot;, output); } } Last edited: 30-Nov-11 10:19 AM

iamunknown · Nov 30, 2011 10:08 AM

This is what I did for the GUI. I dont know much about GUI, so stuck now. Please help me import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; &nbsp; public class GUI extends JFrame { public static void create(String title, String text) { GUI frame = new GUI(text); &nbsp; frame.setTitle(title); //Sets the title frame.setSize(640,480); //Sets the size frame.setLocationRelativeTo(null); //Centers the window frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Actually closes the process when prompted frame.setVisible(true);

iamunknown · Nov 30, 2011 10:10 AM

&nbsp;

iamunknown · Nov 30, 2011 10:11 AM

थे अस्सिग्न्मेन्त इज तो ग्राफइकल्ली दिस्प्लएे अ सोर्तेद लिस्त अफ रेगिस्तेरेद कोउर्सेस अन्द अ रोस्तेर फोर एअच कुर्&zwj;ेन्त कोउर्से विथ थे नमेस अफ &nbsp;स्टुडेन्टस एन्रोल्लेद इन अ सोर्तेद अर्डर बी लस्त नेम।&nbsp;

iamunknown · Nov 30, 2011 10:16 AM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all