deep king Ответов: 2

Мне нужен основной метод, двоичный поиск и метод сортировки


please help me I need this code before this Friday. post only the complete code, please. All classes should be serializable and comparable. The driver is also required for this. The programming language is Java.

If necessary, you can post only the driver class for this project.

Implementing GUI and sorting methods to this is optional, but greatly appreciated.

Problem: you are to create an app for a library. A Library has different members such as students. Members should be able to search for a book by different criteria such as title, author, and subject. As soon as the book is found in the library, then the student will check out the book and this book will be added to the list of the books that the student has borrowed. When a student returns a book, then that book must be remove from his/her list. The information about items and students must be read from files.

Your program must have the input validation such that no user can enter wrong data. Use exception handling whenever possible. In the client class you must use methods. Everything needs to be done through a method call. You are free to add any functionality to your program and any creativity will be appreciated. Your program must read the data from a file. You need three different files for books, students and administrators.

.

Steps to complete your project:
1. There are 6 different classes and you need to implement all these classes and make sure that they work properly by writing client class. You must read the information for the students and books from files to populate the ArrayList for the class students and books.

2. In the main method you must provide the following functionalities Students should be able to do :

o Search by author //must write a method
o Search by subject//must write a method
o Search by topic//must write a method
o Search by keyword//must write a method
o After the item is selected, the item must be added to the student list of

checked out items if the item is available.

Admin people should be able to do the following.

o Search for items o Addanewitem o Delete a new item o Add a student

o Remove a student
o Search for a student

When implementing the client class, you must use many different methods. Everything must be done through a method call. For example for searching a student in the array you must write a method. Codes without any methods will receive no credit.

Before logging out the application all the updated data must be stored in a file. When you run your program all the data must be loaded from the file back to the lists that you are suppose to create for your program.

Description:
In this project you are going to develop a library application. Using this application students will be able to search for books, video CD, journals, and audio CD. Administrators will use this app to add or remove resources from the database in the library. Therefore the main page should have to different options

o Students (id number is required). If student is not found in the list of the students then n error message should be displayed

o Administrators (id number is required). If the id is not found an error message must be displayed

Students
Students should be able to search the data base using different search criteria such as:

 Title
 Subject

 Keywords in the subject

 Keywords in the title

Once the search criteria is declared by the user, then the list of all the available resources must appear on the screen. Once the user selects the desired item, then the status for the item must be changed to check out and the item must be added to the student account. A return date must be specified for the user. When a book is returned by a student, first your app must make sure that the book has been returned on time otherwise a penalty will be added to the user account. If the total penalty is more than 50 dollars on a student account, then a hold will be put on the user account and the student will no longer be able to check out any books.

All the information for the students and resources must be stored in a file therefore every time you log out the system all the info must be saved to a file. As soon as you log in all the info must be read from files and stored in appropriate collections. You must make all your classes serializable

Administrators: Administrators should be able

 To add or remove items to/from the database

 Add or remove students

 Put a hold on a student account

 Search through the students and send a notification to the students who have pass

due item

To implement this application we need the following classes

Item

-String title
-String subject
-String author
-String publisher
-String yearPublished// must be validated -boolean status

-String type// validate type it can only be book, journal audio CD , Video CD

+Item(String t, string s, string a, string p, string y, boolean stat, string typ) +Item()
+all the accessors
+all the mutator

+toString(): String
+equals(Item i): Boolean
+contains(String s)// returns true if the string s is found in the title +compareTo(Item i): int //compare based on the title and author -Validatedate(string d): boolean

2. Person (holds info such as name, last name, ID, email, phone number)

Person

- String name

- String lastName

- String id //must validate the format

- String email //must be validate the format

- String phone//must validate the format

+ Person(String n, string l, string initialed, String em, string p) +person()
+accessors, mutators
+toString(): String

+equals(Person p): Boolean //based on the ID number

+compaerTo(Persom p): int -validateId(String id): boolean -validateemail(String email) : boolean -validate(String phone) : boolean

//based on the last name

3. Library (holds a collection of items)

Library

-ArrayList items

+Library()
+getSize(): int
+add(Item i): Boolean //returns false if the item already exists, need to use equals method from the item class

+remove(item i): boolean //returns false if the item is not in the list, need to use the equals method from the item class
+searchTitle(String title): item //search the array based on the title, returns null if the object not found, need to use the equals method from the item class +searachSubject(String subject): item //search the item based on the subject, return null if the object is not found, need to use the equals method from the item class +searchkeyword(String key): Item // returns the item based on the keyword, the keyword could be in the subject or title of the item. Need to use the contains method from the item class

4. Student

Student

-person
-ArrayList checkedout

+student(Person p)
+accessors, mutators
+equals(Students s) // use the equals method from the person class +addcheckedOut(Item i)// adds the checked out item to the list +toString(): String

5. Students

Students

-ArrayList

+Students()
+add(Student s)
+remove(Student) +serachStudent(String id): Boolean +toString(): String

6. Administrator

Administrator

-ArrayList

+Administrator() +add(Person p) +remove(Person p) +search(Person P) +toString(): String

Here is a list of the subjects that you can use

 Accounting and Finance

 Anthropology

 Area Studies

 Art

 Basic Search

 Biological Sciences

 Business and Management

 Chemistry

 Child Development

 Communication Studies

 Computer Science

 Construction Management

 Criminal Justice

 Design

 Economics

 Education

 Engineering

 English Language and Literature

 Environmental Studies

 Ethnic Studies

 Family and Consumer Science

 Film Studies

 Foreign Languages and Literature

 Geography and Maps

 Geology and Earth Sciences

 Gerontology

 Government and Political Science

 Health and Medical Sciences

 Hellenic Studies

 History

 Humanities

 International Affairs

 International Business

 Journalism

 Kinesiology

 Law

 Library and Information Technology

 Management Information Science

 Marketing

 Mathematics

 Music

 News and Reference

 Nursing

 Philosophy

 Physical Therapy

 Physics and Astronomy
 Psychology
 Public Policy and Administration 

Item.java

   import java.util.StringTokenizer;
   import java.io.Serializable;

 public class Item implements Serializable
{
   String title;
   String subject;
   String author;
   String publisher;
   String yearPublished;//validated?
   boolean status;
   String type; // can only be book, journal, audio cd, or video cd
  
   public Item(String t, String s, String a, String p, String y, boolean stat, String type)
   {
       title = t;
       subject = s;
       author = a;
       publisher = p;
       setYearPublished(y);
       status = stat;
       setType(type);
   }
  
   public Item()
   {
       title = "";
       subject = "";
       author = "";
       publisher = "";
       yearPublished = "";
       status = false;
       type = "";
   }
  
   public boolean contains(String word)
   {
       StringTokenizer token = new StringTokenizer(this.title);
       while(token.hasMoreTokens())
           if(token.nextToken().equalsIgnoreCase(word)) return true;
       return false;
   }
  
   public String toString()
   {
       String toReturn;
       toReturn = this.title + "," + this.subject;
       toReturn += "," + author + "," + this.publisher;
       toReturn += "," + this.yearPublished + "," + this.status + "," + this.type;
       return toReturn;
   }
  
   public boolean validateDate(String date)
   {
       if(this.yearPublished == date) return true;
       else return false;
   }
  
   //compares to another person by last name
   public boolean compareTo(Item other)
   {
       if(!other.title.equalsIgnoreCase(this.title)) return false;
       else if(!other.author.equalsIgnoreCase(this.author)) return false;
       else return true;
   }
//----------------------Setters and Getters----------------------
   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }

   public String getSubject() {
       return subject;
   }

   public void setSubject(String subject) {
       this.subject = subject;
   }

   public String getAuthor() {
       return author;
   }

   public void setAuthor(String author) {
       this.author = author;
   }

   public String getPublisher() {
       return publisher;
   }

   public void setPublisher(String publisher) {
       this.publisher = publisher;
   }

   public String getYearPublished() {
       return yearPublished;
   }

   public void setYearPublished(String yearPublished) {
       if(yearPublished.length() == 4 );
           this.yearPublished = yearPublished;
   }

   public boolean getStatus() {
       return status;
   }

   public void setStatus(boolean status) {
       this.status = status;
   }

   public String getType()
   {
       return type;
   }

   public void setType(String type)
   {
       if(type.equalsIgnoreCase("book") || type.equalsIgnoreCase("cd") || type.equalsIgnoreCase("dvd")
               || type.equalsIgnoreCase("journal"))
           this.type = type;
   }
  
  
  

}


Person.java


public class Person
{
   private String name;
   private String lastName;
   private String id;
   private String email;
   private String phone;
   private boolean goodStanding;
  
   public Person()
   {
       //nothing
   }
  
   public Person(String n, String l, String id, String email, String phone)
   {
       this.name = n;
       this.lastName = l;
       setId(id);
       setEmail(email);
       setPhone(phone);
       goodStanding = true;
      
   }
   //prints the toString of the class person
   public String toString()
   {
       String toReturn;
       toReturn = this.name + " " + this.lastName;
       toReturn += " " + id + " " + this.email;
       toReturn += " " + this.phone;
       return toReturn;
   }
  
   //validates the i.d. of the person
   private boolean validateId(String id)
   {
       if(id.length() != 10)
           return false;
       for(int i = 0; i < id.length(); i++)
       {
           if(Character.isAlphabetic(id.charAt(i))) return false;
       }
       return true;
      
   }
  
   //validates the email of the person
   private boolean validateEmail(String email)
   {
       boolean atMarker = false;
       for(int i = 0; i < email.length(); i++)
       {
           if(email.charAt(i) == '@') atMarker = true;
       }
       if(!atMarker) return false;
       else return true;
   }
  
   //validates the phone number
   private boolean validatePhone(String phone)
   {
       if(phone.length() != 10) return false;
       for(int i = 0; i < phone.length(); i++)
       {
           if(!Character.isDigit(phone.charAt(i))) return false;
       }
       return true;
   }
  
   //compares to another person by last name
   public boolean compareTo(Person other)
   {
       if(!other.lastName.equalsIgnoreCase(this.lastName)) return false;
       else return true;
   }
  
   boolean equals(Person other)
   {
       if(this.id.equalsIgnoreCase(other.id)) return false;
       else return true;
   }
   //----------------------Setters and Getters----------------------
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getLastName() {
       return lastName;
   }
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }
   public String getId() {
       return id;
   }
   private void setId(String id) {
       if(validateId(id)) this.id = id;
       else throw new IllegalArgumentException();
   }
   public String getEmail() {
      
       return email;
   }
   private void setEmail(String email) {
       if(validateEmail(email)) this.email = email;
       else throw new IllegalArgumentException();
   }
   public String getPhone() {
       return phone;
   }
   private void setPhone(String phone) {
       if(validatePhone(phone)) this.phone = phone;
       else throw new IllegalArgumentException();
   }

   public boolean isGoodStanding() {
       return goodStanding;
   }

   public void setGoodStanding(boolean goodStanding) {
       this.goodStanding = goodStanding;
   }
}

Library.java

import java.io.Serializable;
import java.util.ArrayList;
import java.io.Serializable;


public class Library implements Serializable
{
   //arraylist of items variable
   private ArrayList<Item> items;
  
   //constructor that creates an arraylist of items
   public Library()
   {
       items = new ArrayList<Item>();
   }
  
   //get the size of the arraylist
   public int getSize()
   {
       return items.size();
   }
  
   //add item to arraylist ony if it does not already have it
   public boolean add(Item item)
   {
       if(items.contains(item)) return false;
       else
       {
           items.add(item);
           return true;
       }
   }
  
   //only remove the item if it exists
   public boolean remove(Item item)
   {
       if(!items.contains(item)) return false;
       else
       {
           items.remove(item);
           return true;
       }
   }
  
   //searches for input title and if it matches then it returns an arraylist
   //with the same words as the input
   public ArrayList<Item> searchTitle (String input)
   {
       ArrayList<Item> correctTitle = new ArrayList<Item>();
       for(int i = 0; i < items.size(); i++)
       {
           if(input.equalsIgnoreCase(items.get(i).getTitle()))
               correctTitle.add(items.get(i));
       }
      
       //if the arraylist is empty then return null
       if(correctTitle.size() == 0) return null;
       else
           return correctTitle;
   }
  

   //searches for input title and if it matches then it returns an arraylist
   //with the same words as the input
   public ArrayList<Item> searchAuthor (String author)
   {
       ArrayList<Item> correctAuthor = new ArrayList<Item>();
       for(int i = 0; i < items.size(); i++)
       {
           if(author.equalsIgnoreCase(items.get(i).getAuthor()))
               correctAuthor.add(items.get(i));
       }
      
       //if the arraylist is empty then return null
       if(correctAuthor.size() == 0) return null;
       else
           return correctAuthor;
   }
  
  
   public ArrayList<Item> searchSubject(String input)
   {
       ArrayList<Item> correctSubject = new ArrayList<Item>();
       for(int i = 0; i < items.size(); i++)
       {
           if(input.equalsIgnoreCase(items.get(i).getSubject()))
           {
              
               correctSubject.add(items.get(i));
           }
       }
       if(correctSubject.size() == 0) return null;
       else
           return correctSubject;
   }

  
   public ArrayList<Item> searchKeyword(String keyword)
   {
       ArrayList<Item> correctKeyword = new ArrayList<Item>();
       for(int i = 0; i < items.size(); i++)
       {
           if(items.get(i).contains(keyword))
               correctKeyword.add(items.get(i));
       }
      
       if(correctKeyword.size() == 0) return null;
       else
           return correctKeyword;
   }
  
   public String toString()
   {
       String toReturn = "";
       for(int i = 0; i < items.size(); i++)
       {
           toReturn += items.get(i).getTitle() + " " + items.get(i).getAuthor();
       }
       return toReturn;
   }
  
   //turn arraylist into regular array
   public Item[] toArray()
   {
         Item[] it = new Item[items.size()];
         for(int i = 0; i < items.size(); i++)
             it[i] = items.get(i);
         return it;
   }
  
   public ArrayList<Item> getItemArray()
   {
       return items;
   }

}

Student.java

import java.util.ArrayList;


public class Student
{
   Person person;
   private ArrayList<Item> checkout;
  
   Student(Person p)
   {
       person = p;
       checkout = new ArrayList<Item>();
   }
  
   boolean equals(Student other)
   {
       if(!person.getId().equalsIgnoreCase(other.getPerson().getId())) return false;
       else return true;
   }
  
   public void addCheckedOut(Item i)
   {
       checkout.add(i);
   }
  
   public String toString()
   {
       return person.toString();
   }
  
   public boolean hasItem(Item other)
   {
       for(int i = 0; i < checkout.size(); i++)
       {
           if(checkout.get(i).compareTo(other))
               return true;
       }
       return false;
   }
  
   public ArrayList<Item> getCheckout()
   {
       return checkout;
   }
  
   public Person getPerson()
   {
       return person;
   }
}


Administrator.java

import java.util.ArrayList;


public class Administrator
{
   ArrayList<Person> administrators;
  
   Administrator()
   {
       administrators = new ArrayList<Person>();
   }
  
   public void add (Person p)
   {
       administrators.add(p);
   }
  
   public void remove (Person p)
   {
       administrators.remove(p);
   }
  
   public boolean search(Person p)
   {
       for(int i = 0; i < administrators.size(); i++)
           if(administrators.get(i).getId().equals(p)) return true;
       return false;
   }
  
   public boolean searchAdmin(String id)
   {
       for(int i = 0; i < administrators.size(); i++)
           if(administrators.get(i).getId().equals(id)) return true;
       return false;
   }
  
   public String toString()
   {
       String toReturn = "";
       for(int i = 0; i < administrators.size(); i++)
       {
           toReturn = administrators.toString();
       }
       return toReturn;
   }
}

Students.java

import java.util.ArrayList;


public class Students
{
  
   private ArrayList<Student> students;
  
   public Students()
   {
       students = new ArrayList<Student>();
   }
  
   public void add (Student s)
   {
       students.add(s);
   }
  
   public void remove (Student s)
   {
       students.remove(s);
   }
  
   public boolean searchStudent(String id)
   {
       for(int i = 0; i < students.size(); i++)
           if(students.get(i).person.getId().equals(id)) return true;
       return false;
   }
  
   public int getIndexofMatch(String id)
   {
       for(int i = 0; i < students.size(); i++)
           if(students.get(i).person.getId().equals(id)) return i;
       return -1;
   }
  
   public String toString()
   {
       String toReturn = "";
       for(int i = 0; i < students.size(); i++)
       {
           toReturn += students.get(i).person.getName() + " " + students.get(i).person.getLastName();
       }
       return toReturn;
   }
  
   public ArrayList<Student> getStudentArray()
   {
       return students;
   }
}


Что я уже пробовал:

я сделал это большинство из вас, поэтому, пожалуйста, постарайтесь помочь мне как можно скорее.

2 Ответов

Рейтинг:
2

OriginalGriff

Мы не делаем домашнее задание: оно задано не просто так. Она существует для того, чтобы вы думали о том, что вам сказали, и пытались понять это. Он также существует для того, чтобы ваш наставник мог определить области, в которых вы слабы, и сосредоточить больше внимания на корректирующих действиях.

Попробуйте сами, возможно, вы обнаружите, что это не так сложно, как вы думаете!

Если вы столкнетесь с конкретной проблемой, то, пожалуйста, спросите об этом, и мы сделаем все возможное, чтобы помочь. Но мы не собираемся делать все это для вас!


Рейтинг:
0

Richard MacCutchan

Цитата:
публикуйте только полный код
Извините, но этого просто не произойдет. Это ваша домашняя работа, так что вы должны сделать это сами. Если у вас есть конкретные вопросы, то люди будут пытаться помочь вам, но они не будут делать вашу работу.