Advertisement
Guest User

задача за самостоятелна работа java

a guest
Mar 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. -----------1ви файл ILibraryBook
  2.  
  3. public interface ILibraryBook {
  4. public void get(Reader rdr);
  5. public void get();
  6.  
  7. }
  8.  
  9. ------------2ри файл IReader
  10.  
  11. public interface IReader {
  12. public void get(LibraryBook obj);
  13. public void ret(LibraryBook obj);
  14. }
  15.  
  16. -----------3ти файл Applicant
  17.  
  18. import java.util.GregorianCalendar;
  19.  
  20. public class Applicant {
  21. private String name;
  22. private GregorianCalendar date;
  23. private double uspeh;
  24.  
  25. public Applicant(GregorianCalendar birth, String name, double uspeh)
  26. {
  27. this.name = name;
  28. this.date = birth;
  29. this.uspeh = uspeh;
  30. }
  31.  
  32. public String getName()
  33. {
  34. return this.name;
  35. }
  36. public void setName(String name)
  37. {
  38. this.name = name;
  39. }
  40. public GregorianCalendar getDate()
  41. {
  42. return this.date;
  43. }
  44. public void setDate(GregorianCalendar birth)
  45. {
  46. this.date = birth;
  47. }
  48. public double getUspeh()
  49. {
  50. return this.uspeh;
  51. }
  52. public void setUspeh(double uspeh)
  53. {
  54. this.uspeh = uspeh;
  55. }
  56. public String toString()
  57. {
  58. return this.name + " " + this.date + " " + this.uspeh + " ";
  59. }
  60. }
  61.  
  62. ---------------------4ти файл Student
  63.  
  64. import java.util.GregorianCalendar;
  65.  
  66. public class Student extends Applicant implements Comparable<Object>{
  67. private String FN;
  68.  
  69. public Student(String name, String FN) {
  70. super(new GregorianCalendar(),name,0.0);
  71. this.FN = FN;
  72. }
  73.  
  74. public Student(GregorianCalendar date, String name, double uspeh, String FN) {
  75. /*super.setDate(date);
  76. super.setName(name);
  77. super.setUspeh(uspeh);*/
  78. super(date,name,uspeh);
  79. this.FN = FN;
  80. }
  81.  
  82. public boolean equals (Object r) {
  83. return this.FN.equals(((Student)r).FN);
  84. }
  85.  
  86. public String getFN() {
  87. return this.FN;
  88. }
  89.  
  90. public void setFN(String FN) {
  91. this.FN = FN;
  92. }
  93.  
  94. public String toString() {
  95. return super.toString() + " " + this.FN;
  96. }
  97.  
  98. public int compareTo(Object r) {
  99. return this.FN.compareTo(((Student)r).FN);
  100. }
  101. }
  102.  
  103. ------------------------------5ти файл Reader
  104.  
  105. import java.util.GregorianCalendar;
  106.  
  107. public class Reader extends Student implements IReader,Comparable<Object>{
  108. private LibraryBook library_book_obj= new LibraryBook("");
  109.  
  110. public Reader(String nm,String fn) {
  111. super(nm,fn);
  112. }
  113.  
  114. public Reader(GregorianCalendar date, String name, double uspeh, String FN) {
  115. super(date,name,uspeh,FN);
  116. }
  117.  
  118. public LibraryBook getLibraryBook() {
  119. return this.library_book_obj;
  120. }
  121.  
  122. public String toString() {
  123. return super.toString() + " " + this.library_book_obj.toString();
  124. }
  125.  
  126. public int compareTo(Object r) {
  127. return super.compareTo(r);
  128. }
  129.  
  130. public void get(LibraryBook lb) {
  131. this.library_book_obj = lb;
  132. }
  133.  
  134. public void ret(LibraryBook lb) {
  135. lb.ret();
  136. library_book_obj = null;
  137. }
  138. }
  139.  
  140. ---------------------------6ти файл LibraryBook
  141.  
  142. public class LibraryBook implements ILibraryBook,Comparable<Object>{
  143. private Reader reader_obj = new Reader(null, null, 0, null);
  144. private String book_name;
  145. private boolean status;
  146.  
  147. public LibraryBook(String bn) {
  148. this.book_name = bn;
  149. }
  150.  
  151. public LibraryBook(String bn,boolean st) {
  152. this.book_name = bn;
  153. this.status = st;
  154. }
  155.  
  156. public Reader getReader() {
  157. return reader_obj;
  158. }
  159.  
  160. public String getBookName() {
  161. return this.book_name;
  162. }
  163.  
  164. public void setBookName(String book_name) {
  165. this.book_name = book_name;
  166. }
  167.  
  168. public String getStatusText() {
  169. if(this.status) {
  170. return "zaeta";
  171. }
  172. return "svobodna";
  173. }
  174.  
  175. public boolean getStatus() {
  176. return this.status;
  177. }
  178.  
  179. public void setStatus(boolean status) {
  180. this.status = status;
  181. }
  182.  
  183. public String toString() {
  184. return reader_obj.toString() + " " + book_name + " " + this.getStatusText();
  185. }
  186.  
  187. public int compareTo(Object r) {
  188. return this.compareTo((LibraryBook)r).toString()); // <-----тук има грешка и подчертава всичко включително след this.
  189. }
  190.  
  191. public void get(Reader rdr) {
  192. this.reader_obj = null;
  193. this.status = true;
  194. }
  195.  
  196. public void ret() {
  197. this.reader_obj = null;
  198. this.status = false;
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement