/** collegeDetail is a function which is read college detail from file and store in queue */ public void readCollageDetail() { try { // Reading the college data from file BufferedReader br = new BufferedReader( new FileReader( "C:/Users/khemanshu/workspace/Assignment/src/QueueImplemetation/college.txt")); while ((line = br.readLine()) != null) { String[] token = line.split(","); if (token.length < 2) continue; Colleges collages = new Colleges(); collages.setName(token[0]); collages.setSeatAvaliable(Integer.parseInt(token[1])); collegeQueue.enqueue(collages); collegeList.add(collages); } br.close(); } catch (FileNotFoundException e) { System.out.println(e); } catch (IOException e) { System.out.println(e); } }
/** * SeatAllotment is a function which is used to allot a seat of desire college if seat is * available. */ void SeatAllotment() { int collegeCounter = calculteTotalSeat(); int sizeStudent = studentQueue.getSize(); int sizeColllege = collegeQueue.getSize(); Colleges colleges = new Colleges(); Student student = new Student(); while (sizeStudent != 0) { if (collegeCounter == 0) break; student = (Student) studentQueue.dequeue(); System.out.println("Student Name ->" + student.getName() + "\n" + "Select any college"); showListOfCollage(); String name = ValidationForCollegeName(); for (int count = 0; count < sizeColllege; count++) { colleges = (Colleges) collegeQueue.dequeue(); if (colleges.getName().equalsIgnoreCase(name) == true) { student.setCollegeName(name); colleges.setSeatAvaliable(colleges.getSeatAvaliable() - 1); } collegeQueue.enqueue(colleges); } System.out.println("Allotement is successfully done"); studentQueue.enqueue(student); sizeStudent--; collegeCounter--; } }