Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.26 KB | None | 0 0
  1.  
  2. public interface ILibraryBook {
  3.     public void get(Reader rdr);
  4.     public void ret();
  5. }
  6.  
  7. public interface IReader {
  8.     public void get(LibraryBook book);
  9.     public void ret();
  10. }
  11. import java.util.GregorianCalendar;
  12.  
  13. public class Applicant {
  14.     protected String name;
  15.     protected double mark;
  16.     protected GregorianCalendar date;
  17.     public Applicant(GregorianCalendar date, String name, double mark)
  18.     {
  19.         this.date=date;
  20.         this.name=name;
  21.         this.mark=mark;
  22.     }
  23.    
  24.     public String getName() {
  25.         return name;
  26.     }
  27.     public void setName(String name) {
  28.         this.name = name;
  29.     }
  30.     public double getMarks() {
  31.         return mark;
  32.     }
  33.     public void setMarks(double marks) {
  34.         this.mark = marks;
  35.     }
  36.     public GregorianCalendar getDate() {
  37.         return date;
  38.     }
  39.     public void setDate(GregorianCalendar date) {
  40.         this.date = date;
  41.     }
  42.     public String toString()
  43.     {
  44.         return "Name: "+this.name+", Date: "+date.toString()+", Mark: "+this.mark;
  45.     }
  46. }
  47. import java.util.GregorianCalendar;
  48.  
  49. public class Student extends Applicant implements Comparable {
  50.    
  51.     protected String fn;
  52.    
  53.     public Student(GregorianCalendar date, String name, double mark, String fn) {
  54.         super(date, name, mark);
  55.         this.fn=fn;
  56.     }
  57.     public Student(String name, String fn) {
  58.         super(new GregorianCalendar(), name, 0.);
  59.         this.fn=fn;
  60.     }
  61.  
  62.     public String getFn() {
  63.         return fn;
  64.     }
  65.  
  66.     public void setFn(String fn) {
  67.         this.fn = fn;
  68.     }
  69.  
  70.     public int compareTo(Object stud) {
  71.         return this.fn.compareTo(((Student)stud).getFn());
  72.     }
  73.     public boolean equals(Object stud) {
  74.         return this.fn.equals(((Student)stud).getFn());
  75.     }
  76.     public String toString()
  77.     {
  78.         return super.toString()+", FN: "+this.fn;
  79.     }
  80.    
  81. }
  82. import java.util.GregorianCalendar;
  83.  
  84. public class Reader extends Student implements IReader,Comparable{
  85.  
  86.     private LibraryBook readerBook;
  87.     public Reader(String name, String fn)
  88.     {
  89.         super(name,fn);
  90.     }
  91.     public Reader(GregorianCalendar date, String name, double mark, String fn) {
  92.         super(date, name, mark,fn);
  93.     }
  94.    
  95.     public boolean equals(Object o)
  96.     {
  97.         return super.equals(o);
  98.     }
  99.     public int compareTo(Object o) {
  100.         return super.compareTo(o);
  101.     }
  102.     public String toString()
  103.     {
  104.         return super.toString();
  105.     }
  106.  
  107.     public void get(LibraryBook book) {
  108.         this.readerBook=book;
  109.     }
  110.  
  111.     public void ret() {
  112.         this.readerBook=null;
  113.     }
  114.  
  115. }
  116.  
  117. public class LibraryBook implements ILibraryBook,Comparable{
  118.     private String name;
  119.     private Reader reader;
  120.     private boolean status;
  121.    
  122.     public LibraryBook(String name)
  123.     {
  124.         this.setName(name);
  125.         this.setStatus(false);
  126.     }
  127.     public LibraryBook(String name, boolean status)
  128.     {
  129.         this.setName(name);
  130.         this.setStatus(status);
  131.     }
  132.     public Reader getReader() {
  133.         return reader;
  134.     }
  135.     public void setReader(Reader reader) {
  136.         this.reader = reader;
  137.     }
  138.     public String getName() {
  139.         return name;
  140.     }
  141.     public void setName(String name) {
  142.         this.name = name;
  143.     }
  144.     public boolean isStatus() {
  145.         return status;
  146.     }
  147.     public void setStatus(boolean status) {
  148.         this.status = status;
  149.     }
  150.     public int compareTo(Object book)
  151.     {
  152.         return this.toString().compareTo(((LibraryBook)book).toString());
  153.     }
  154.     public String toString()
  155.     {
  156.         return "Name: "+this.name+",Status: "+((status)?"Occupied, Reader - "+this.reader.toString():"Unoccupied");
  157.        
  158.     }
  159.    
  160.     public void get(Reader rdr) {
  161.         if(this.status) return;
  162.         this.reader=rdr;
  163.         this.status=true;
  164.         rdr.get(this);
  165.     }
  166.    
  167.     public void ret() {
  168.         this.reader.ret();
  169.         this.reader=null;
  170.         this.status=false;
  171.     }
  172. }
  173.  
  174. import java.io.File;
  175. import java.io.IOException;
  176. import java.util.ArrayList;
  177. import java.util.List;
  178. import java.util.Scanner;
  179.  
  180. public class Main {
  181.  
  182.     public static void readFile(String fName, ListLibraryBook lib)
  183.     {
  184.         lib.clear();
  185.         try
  186.         {
  187.             Scanner sc=new Scanner(new File(fName));
  188.             while(sc.hasNextLine())
  189.             {
  190.                 lib.add(new LibraryBook(sc.next()));
  191.             }
  192.             sc.close();
  193.         }
  194.         catch(IOException e)
  195.         {
  196.             e.printStackTrace();
  197.         }
  198.     }
  199.     public static void main(String[] args)
  200.     {
  201.         Library lib=new Library(DJava Secret Folder with UpdateUPR5srcbooks.txt,DJava Secret Folder with UpdateUPR5srcreaders.txt);
  202.         lib.print();
  203.         lib.borrowing(1, 3);
  204.         lib.print();
  205.         lib.sort();
  206.         lib.print();
  207.         System.out.println(lib.equalBooks(1,3));
  208.         System.out.println(lib.equalReaders(0, 1));
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement