Advertisement
thecodesalim

Untitled

Feb 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. import java.util.*;
  2. public class LabClass{
  3. private String instructor;
  4. private String room;
  5. private String timeAndDate;
  6. private int classCapacity;
  7. private ArrayList<Student>classList;
  8.  
  9. public LabClass(int newClassCapacity){
  10. classCapacity = newClassCapacity;
  11. classList = new ArrayList<Student>();
  12. }
  13.  
  14. public String getInstructor(){
  15. return instructor;
  16. }
  17.  
  18. public String getRoom(){
  19. return room;
  20. }
  21.  
  22. public String getTimeAndDate(){
  23. return timeAndDate;
  24. }
  25.  
  26. public void setInstructor(String newInstructor){
  27. instructor = newInstructor;
  28. }
  29.  
  30. public void setRoom(String newRoom){
  31. room = newRoom;
  32. }
  33.  
  34. public void setTimeAndDate(String newTimeAndDate){
  35. timeAndDate = newTimeAndDate;
  36. }
  37.  
  38. public int getSize(){
  39. return classList.size();
  40. }
  41.  
  42. public void addStudent(Student item)
  43. {
  44. if(classList.size()<classCapacity){
  45. classList.add(item);
  46. }
  47. else{
  48. System.out.println("full capacity of class");
  49. }
  50. }
  51.  
  52. public Student getSearchName(String searchName){
  53. String itemName;
  54. Student foundItem = null;
  55. int index =0;
  56. boolean found = false;
  57.  
  58. while(index<classList.size() && !found){
  59. itemName=classList.get(index).getName();
  60. if(itemName.equals(searchName)){
  61. found = true;
  62. foundItem = classList.get(index);
  63. }
  64. else{
  65. index++;
  66. }
  67. }
  68. return foundItem;
  69. }
  70. public Student getSearchId(String searchId){
  71. String itemId;
  72. Student foundItem = null;
  73. int index =0;
  74. boolean found = false;
  75.  
  76. while(index<classList.size() && !found){
  77. itemId=classList.get(index).getStudentID();
  78. if(itemId.equals(searchId)){
  79. found = true;
  80. foundItem = classList.get(index);
  81. }
  82. else{
  83. index++;
  84. }
  85. }
  86. return foundItem;
  87. }
  88. public void printClassListV2(){
  89. Iterator itr = classList.iterator();
  90. while(itr.hasNext()) {
  91. Object element = itr.next();
  92. System.out.print(element + " ");
  93. }
  94. System.out.println(print());
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement