Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tester Class
- ---------------------------------------------------------------------------------------------
- import java.util.*;
- public class Tester {
- public static void studentOptions(Students users){
- Library lib=new Library();
- Scanner test=new Scanner(System.in);
- boolean leave = false;
- do {
- System.out.println("Press 1 Check out");
- System.out.println("Press 2: Return");
- System.out.println("Press 3:Compare");
- System.out.println("Press 4: Log out");
- int choice =test.nextInt();
- switch (choice) {
- case 1:
- lib.checkout(users);
- break;
- case 2:
- users.returnBooks();
- break;
- case 3:
- lib.compare_books();
- break;
- case 4:
- leave = true;
- break;
- }
- } while (leave == false);
- }
- public static void adminOptions(){
- Library lib=new Library();
- Scanner test=new Scanner(System.in);
- boolean leave = false;
- do {
- System.out.println("Press 1 to list all students");
- System.out.println("Press 2: To add a student");
- System.out.println("Press 3: To remove a student");
- System.out.println("Press 4: To search for a student");
- System.out.println("Press 5: to add a book");
- System.out.println("Press 6: to remove for a book");
- System.out.println("Press 7: to search a book");
- System.out.println("Press 8: Checkout a book");
- System.out.println("Press 9: Return a book");
- System.out.println("Press 10 to Compare Books");
- System.out.println("Press 11: to Go to Menu");
- int choice =test.nextInt();
- switch (choice) {
- case 1:
- lib.liststudents();
- break;
- case 2:
- lib.add_students();
- break;
- case 3:
- System.out.println("Enter Student Number: ");
- Scanner scan=new Scanner(System.in);
- int search= scan.nextInt();
- lib.removestudents(search);
- break;
- case 4:
- lib.search_students();
- break;
- case 5:
- lib.add_books();
- break;
- case 6:
- lib.remove_books();
- break;
- case 7:
- lib.search_books();
- break;
- case 8:
- lib.checkout(null);
- break;
- case 9:
- lib.getBookBack(null);
- break;
- case 10:
- lib.compare_books();
- case 11:
- leave = true;
- break;
- }
- } while (leave == false);
- }
- public static void main(String[] args) {
- Students user = null;
- Library lib=new Library();
- Scanner test=new Scanner(System.in);
- boolean loop = true;
- while(loop){
- System.out.println("Bramalea Secondary School Library");
- System.out.println("Press 1: Student Login");
- System.out.println("Press 2: Admin Login");
- int x= test.nextInt();
- switch (x) {
- case 1:
- System.out.println("Enter student number: ");
- int num = test.nextInt();
- boolean isUser = false;
- for (int counter = 0; counter < Library.students.size(); counter++){
- if (Library.students.get(counter).getstudentid() == num){
- isUser = true;
- break;
- }
- }
- if (isUser == true){
- user = lib.search_studentsPlus(num);
- System.out.println("Hello, Student ");
- studentOptions(user);
- } else {
- System.out.println("Not Student");
- }
- break;
- case 2:
- String password = "";
- boolean firstTime =false;
- do{
- if (firstTime == false){
- System.out.println("Status: Librarian");
- System.out.println("please enter your admin password: ");
- password=test.next();
- firstTime = true;
- adminOptions();
- } else {
- System.out.println("Incorrect the Password");
- System.out.println("please enter the password");
- password=test.next();
- }
- } while (!password.matches("admin"));
- }
- }
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------------Books Class
- ---------------------------------------------------------------------------------------------------------------------------------------
- public class Books {
- private String title;
- private String author;
- private int ISBN;
- private String category;
- private double cost;
- private double rating;
- public Books (String titleofbook, String person, int ISBNnum, String genre, double costofbook, double starrating){
- title=titleofbook;
- author=person;
- ISBN= ISBNnum;
- category=genre;
- cost=costofbook;
- rating=starrating;
- }
- public String getAuthor() {
- return author;
- }
- public String getCategory() {
- return category;
- }
- public double getCost() {
- return cost;
- }
- public int getISBN() {
- return ISBN;
- }
- public double getrating() {
- return rating;
- }
- public String getTitle(){
- return title;
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------------Library Class
- ---------------------------------------------------------------------------------------------------------------------------------------
- import java.util.*;
- import java.text.SimpleDateFormat;
- public class Library {
- public ArrayList<Books> books=new ArrayList<Books>();
- public static ArrayList<Students> students=new ArrayList<Students>();
- public void add_students() {
- Scanner scan=new Scanner(System.in);
- System.out.println("How many students would you like to add: ");
- int numofstudents=scan.nextInt();
- for(int i=0;i<numofstudents;i++)
- {
- System.out.println("Enter first name");
- String firstname=scan.next();
- System.out.println("Enter last name");
- String lastname=scan.next();
- System.out.println("Enter student number");
- int studentNum=scan.nextInt();
- students.add((new Students(firstname, lastname, studentNum,0)));
- }
- }
- public void add_books() {
- Scanner scan=new Scanner(System.in);
- System.out.println("How many books would you like to add: ");
- int numofstudents=scan.nextInt();
- int m ;
- for(int i=0;i<numofstudents;i++)
- {
- m = i+1;
- System.out.println("For the "+m+" book");
- scan.nextLine();
- System.out.println("Enter book's name");
- String bookname=scan.nextLine();
- System.out.println("Enter the Author's Name");
- String authorname=scan.nextLine();
- System.out.println("Enter the ISBN number");
- int ISBN=scan.nextInt();
- scan.nextLine();
- System.out.println("Please Enter the Genre of the book");
- String category=scan.nextLine();
- System.out.println("Please Enter the cost of the book");
- double cost=scan.nextDouble();
- System.out.println("Please Enter the Rating of the the book");
- double rating =scan.nextDouble();
- books.add((new Books(bookname, authorname, ISBN,category,cost, rating )));
- }
- }
- public void search_books() {
- {
- Scanner scan=new Scanner(System.in);
- System.out.println("Enter the ISBN of the book");
- int search= scan.nextInt();
- for(int i = 0;i<books.size();i++){
- if (books.get(i).getISBN()==search)
- {
- System.out.println("Title: "+books.get(i).getTitle());
- System.out.println("Author Name: "+books.get(i).getAuthor());
- System.out.println("Genre: "+books.get(i).getCategory());
- System.out.println("Cost: "+books.get(i).getCost());
- System.out.println("ISBN: "+books.get(i).getISBN());
- System.out.println("Stars: "+books.get(i).getrating());
- System.out.println("\n");
- }
- }
- }
- }
- public void liststudents(){
- System.out.println("Student List");
- System.out.println("______________________________");
- System.out.println(" ");
- for(Students x : students){
- System.out.println("First Name: "+x.getfirstname());
- System.out.println("Last Name "+x.getlastname());
- System.out.println("Student Number: "+x.getstudentid());
- System.out.println("Student Fines: "+x.getstudentfines());
- System.out.println("\n");;
- }
- }
- public void compare_books(){
- Scanner scan=new Scanner(System.in);
- System.out.println("Enter the ISBN of the first book");
- int searchkey= scan.nextInt();
- System.out.println("Enter the ISBN of the second");
- int searchkey2=scan.nextInt();
- for(int i = 0;i<books.size();i++){
- if (books.get(i).getISBN()==searchkey)
- {
- System.out.println("Title: "+books.get(i).getTitle());
- System.out.println("Author: "+books.get(i).getAuthor());
- System.out.println("Category: "+books.get(i).getCategory());
- System.out.println("Cost(in CAD): "+books.get(i).getCost());
- System.out.println("ISBN: "+books.get(i).getISBN());
- System.out.println("Star rating"+books.get(i).getrating());
- }
- for(int j = 0;i<books.size();j++)
- if (books.get(i).getISBN()==searchkey2)
- {
- System.out.println("Title: "+books.get(i).getTitle());
- System.out.println("Author: "+books.get(i).getAuthor());
- System.out.println("Category: "+books.get(i).getCategory());
- System.out.println("Cost(in CAD): "+books.get(i).getCost());
- System.out.println("ISBN: "+books.get(i).getISBN());
- System.out.println("Star rating"+books.get(i).getrating());
- }
- }
- }
- public void listbooks(){
- System.out.println("Book List");
- for(Books y: books){
- System.out.println("Title of the Book: "+y.getTitle());
- System.out.println("Author of the book: "+y.getAuthor());
- System.out.println("Genre of the Book"+y.getCategory());
- System.out.println("Cost of the book"+y.getCost());
- System.out.println("Rating of the book"+y.getrating());
- System.out.println("ISBN of the book: "+y.getISBN());
- System.out.println("\n");
- }
- }
- public void removestudents(int num) {
- Scanner scan=new Scanner(System.in);
- for(int u = 0;u<students.size();u++){
- if (students.get(u).getstudentid() == num)
- {
- students.remove(u);
- }
- }
- }
- public void remove_books(){
- Scanner scan=new Scanner(System.in);
- System.out.println("Enter the ISBN of the book");
- int isbnsearch= scan.nextInt();
- for(int i = 0;i<books.size();i++){
- if (books.get(i).getISBN()==isbnsearch)
- {
- System.out.println("Title: "+books.get(i).getTitle());
- System.out.println("Author: "+books.get(i).getAuthor());
- System.out.println("Genre: "+books.get(i).getCategory());
- System.out.println("Cost of book: "+books.get(i).getCost());
- System.out.println("Get Book ISBN: "+books.get(i).getISBN());
- System.out.println("Book Rating: "+books.get(i).getrating());
- System.out.println("Are you sure you want to remove this book? (Y)es/(N)o");
- String yes=scan.next();
- yes.toLowerCase();
- if(yes.matches("y")){
- books.remove(i);
- System.out.println("This book has been Removed");
- }
- else{
- System.out.println("This book has not been Removed");
- }
- }
- }
- }
- public void search_students() {
- {
- Scanner scan=new Scanner(System.in);
- System.out.println("Enter the Student Number: ");
- int search= scan.nextInt();
- for(int i = 0;i<students.size();i++){
- if (students.get(i).getstudentid()==search)
- {
- System.out.println("First Name: "+students.get(i).getfirstname());
- System.out.println("Last Name: "+students.get(i).getlastname());
- System.out.println("Student ID: "+students.get(i).getstudentid());
- System.out.println("OutStanding Fines: "+students.get(i).getstudentfines());
- System.out.println();
- System.out.println("\n");
- }
- }
- }
- }
- public Students search_studentsPlus(int num) {
- Students s = null;
- for(int i = 0;i<students.size();i++){
- if (students.get(i).getstudentid()==num)
- {
- s = students.get(i);
- }
- }
- return(s);
- }
- public void checkout(Students user) {
- Scanner input = new Scanner(System.in);
- int index = 0;
- System.out.println("Please Enter the ISBN of the book");
- int search = input.nextInt();
- for(int i1 = 0;i1<books.size();i1++){
- if (books.get(i1).getISBN()==search)
- {
- index = i1;
- user.checkOut(books.get(i1));
- user.displayBooks();
- break;
- }
- }
- books.remove(index);
- }
- public void getBookBack (Books b){
- books.add(b);
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------------Students Class
- ---------------------------------------------------------------------------------------------------------------------------------------
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Students extends Library {
- private String firstname;
- private String lastname;
- private int studentid;
- private double studentfines;
- private ArrayList<Books> books = new ArrayList<Books>();
- public Students(String firstnam, String lastnam, int id,double fines)
- {
- firstname=firstnam;
- lastname=lastnam;
- studentid=id;
- studentfines=fines;
- }
- public String getfirstname() {
- return firstname;
- }
- public String getlastname() {
- return lastname;
- }
- public int getstudentid() {
- return studentid;
- }
- public double getstudentfines() {
- return studentfines;
- }
- public void checkOut(Books book){
- books.add(book);
- }
- public void returnBooks(){
- Library lib=new Library();
- Scanner input=new Scanner(System.in);
- for(int i = 0; i < books.size(); i++){
- System.out.println("Press (" + i + ") to return: " + books.get(i).getTitle() + " by " + books.get(i).getAuthor());
- }
- int choice = input.nextInt();
- lib.getBookBack(books.get(choice));
- books.remove(choice);
- }
- public void displayBooks(){
- System.out.println(firstname + lastname + "Student ID: " + studentid + " has: ");
- for(Books x : books){
- System.out.print(x.getTitle() + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement