Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Muhammad P | Tester Class |
- ------------------------------------------------------------------------------------------------------------------------
- package BramaleaLib;
- import java.util.*;
- public class Tester {
- public static void studentOptions(Library lib, Students users){
- Scanner test=new Scanner(System.in);
- boolean leave = false;
- do {
- System.out.println("Press 1 Check out a book");
- System.out.println("Press 2: Return a book");
- System.out.println("Press 3: to Search for a book");
- System.out.println("Press 4: to Compare two books");
- System.out.println("Press 5: Log out");
- int choice =test.nextInt();
- switch (choice) {
- case 1:
- lib.checkout(users);
- break;
- case 2:
- users.returnBooks(lib);
- break;
- case 3:
- lib.search_books();
- break;
- case 4:
- lib.compare_books();
- break;
- case 5:
- leave = true;
- break;
- }
- } while (leave == false);
- }
- public static void adminOptions(Library lib){
- String bookname = "", authorname = "", category = "";
- double cost = 0, rating = 0;
- int ISBN = 0;
- 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 to Compare Books");
- System.out.println("Press 9: 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:
- System.out.println("How many books would you like to add: ");
- int numofstudents=test.nextInt();
- int m ;
- for(int i=0;i<numofstudents;i++)
- {
- m = i+1;
- System.out.println("For the "+m+" book");
- test.nextLine();
- System.out.println("Enter book's name");
- bookname=test.nextLine();
- System.out.println("Enter the Author's Name");
- authorname=test.nextLine();
- System.out.println("Enter the ISBN number");
- ISBN=test.nextInt();
- test.nextLine();
- System.out.println("Please Enter the Genre of the book");
- category=test.nextLine();
- System.out.println("Please Enter the cost of the book");
- cost=test.nextDouble();
- System.out.println("Please Enter the Rating of the the book");
- rating =test.nextDouble();
- lib.add_books(bookname, authorname, ISBN, category, cost, rating);
- }
- break;
- case 6:
- lib.remove_books();
- break;
- case 7:
- lib.search_books();
- break;
- case 8:
- lib.compare_books();
- case 9:
- 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(lib, user);
- } else {
- System.out.println("Not Student");
- }
- break;
- case 2:
- System.out.println("Status: Librarian");
- String password = "";
- do{
- System.out.println("please enter your admin password: ");
- password=test.next();
- if (password.matches("admin")){
- adminOptions(lib);
- } else {
- System.out.println("Incorrect Password");
- }
- }while (!password.matches("admin"));
- }
- }
- }
- }
- ------------------------------------------------------------------------------------------------------------------------
- Muhammad P | Library Class |
- ------------------------------------------------------------------------------------------------------------------------
- package BramaleaLib;
- import java.util.*;
- import java.text.SimpleDateFormat;
- public class Library {
- private 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(String bookname, String authorname, int ISBN, String category, double cost, double rating) {
- 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();
- boolean check = true;
- 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");
- check = false;
- }
- }
- if(check==true){
- System.out.println("Sorry, We aren't currently carrying this Book.");
- }
- }
- }
- 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's of the books you want to compare:");
- int searchkey1= scan.nextInt();
- System.out.println("Enter the ISBn of the second book: ");
- int searchkey2= scan.nextInt();
- boolean check = true;
- for(int i =0; i<books.size();i++){
- if(books.get(i).getISBN()==(searchkey1)){
- System.out.println(" ");
- System.out.println("___________________________________");
- 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("ISBN: "+books.get(i).getISBN());
- System.out.println("Cost: "+books.get(i).getCost());
- System.out.println("Rating: "+books.get(i).getrating());
- System.out.println("");
- check = false;
- }
- }
- if(check==true){
- System.out.println("We are not carrying this book.");
- }
- for(int i =0; i<books.size();i++){
- if(books.get(i).getISBN()==(searchkey2)){
- System.out.println("______________________________________________");
- 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("ISBN: "+books.get(i).getISBN());
- System.out.println("Cost: "+books.get(i).getCost());
- System.out.println("Rating: "+books.get(i).getrating());
- System.out.println("");
- check = false;
- }
- }
- if(check==true){
- System.out.println("We are not carrying this book.");
- }
- }
- public void removestudents(int num) {
- boolean check = true;
- Scanner scan=new Scanner(System.in);
- for(int u = 0;u<students.size();u++){
- if (students.get(u).getstudentid() == num)
- {
- students.remove(u);
- }
- check = false;
- }
- if(check==true){
- System.out.println("Student Not found: ");
- }
- }
- public void remove_books(){
- Scanner scan=new Scanner(System.in);
- System.out.println("Enter the ISBN of the book");
- int isbnsearch= scan.nextInt();
- boolean check = true;
- 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();
- check = false;
- 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");
- }
- check = false;
- }
- }
- if(check==true){
- System.out.println("Book Does not Exist");
- System.out.println("-------------------------------------------");
- }
- }
- public void search_students() {
- {
- Scanner scan=new Scanner(System.in);
- System.out.println("Enter the Student Number: ");
- int search= scan.nextInt();
- boolean check = true;
- 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");
- check = false;
- }
- }
- if(check==true){
- System.out.println("Student has not been registered");
- System.out.println("-------------------------------------------");
- }
- }
- }
- 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) {
- showBooks();
- 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 i = 0;i<books.size();i++){
- if (books.get(i).getISBN()==search)
- {
- index = i;
- user.checkOut(books.get(i));
- break;
- }
- }
- user.displayBooks();
- books.remove(index);
- }
- public void getBookBack(Books b){
- books.add(b);
- }
- public void showBooks(){
- int num = 1;
- for(Books moho : books){
- System.out.println(num + ") " + moho.getTitle() + " by " + moho.getAuthor() + " [ISBN: " + moho.getISBN() + "]");
- num++;
- }
- }
- }
- ------------------------------------------------------------------------------------------------------------------------
- Muhammad P | Student Class |
- ------------------------------------------------------------------------------------------------------------------------
- package BramaleaLib;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Students{
- 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){
- 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.print(firstname + " " + lastname + " " + "(" + studentid + ") has: ");
- for(Books x : books){
- System.out.print(x.getTitle() + "\n");
- }
- }
- }
- ------------------------------------------------------------------------------------------------------------------------
- Muhammad P | Books Class |
- ------------------------------------------------------------------------------------------------------------------------
- package BramaleaLib;
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement