/** showListOfCollage is a function which is show list of college in which seat is available */ void showListOfCollage() { int size = collegeQueue.getSize(); Colleges colleges = new Colleges(); System.out.println("College Name" + "\t" + "Seats"); for (int count = 0; count < size; count++) { colleges = (Colleges) collegeQueue.dequeue(); if (colleges.getSeatAvaliable() > 0) { System.out.println(colleges.getName() + "\t" + colleges.getSeatAvaliable()); collegeQueue.enqueue(colleges); } } }
/** * 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--; } }
/** * calculteTotalSeat is a function which is used to calculated total available seat in all college * * @return total seat */ int calculteTotalSeat() { int totalSeat = 0; for (Colleges college : collegeList) { totalSeat += college.getSeatAvaliable(); } return totalSeat; }
/** * ValidationForCollegeName is a recursive function which is used for validation that entered * college name is correct or not */ String ValidationForCollegeName() { boolean flag = false; Scanner scanner = new Scanner(System.in); String name = scanner.nextLine(); for (Colleges collage : collegeList) { if (collage.getName().equalsIgnoreCase(name) && collage.getSeatAvaliable() > 0) { flag = true; return name; } } if (!flag) { System.out.println("please enter correct college name"); name = ValidationForCollegeName(); } return name; }