Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import javax.print.DocFlavor.INPUT_STREAM;
- import java.awt.im.spi.InputMethod;
- import java.lang.reflect.Array;
- import java.util.ArrayList;
- public class Management
- {
- public static void main(String[] args)
- {
- menu();
- }
- static ArrayList<Student> students = new ArrayList<Student>();
- static ArrayList<Book> books = new ArrayList<Book>();
- static ArrayList<Magazine> magazines = new ArrayList<Magazine>();
- static ArrayList<Item> items = new ArrayList<Item>();
- static ArrayList<Loan> loans = new ArrayList<Loan>();
- public static void menu()
- {
- System.out.println(
- "[+] To Insert New Student Press: 1"+
- "\n[+] To Insert New Book Press: 2"+
- "\n[+] To Insert New Magazine Press: 3"+
- "\n[+] To Insert New Loan Press: 4"+
- "\n[+] To Delete Loan Press: 5"+
- "\n[+] To Print Students Press: 6"+
- "\n[+] To Print Books and Magazines Press: 7"+
- "\n[+] To Print Loans Press: 8"+
- "\n[+] For Exit Press: x or X"+
- "\n[>] Insert Choice: ");
- Scanner input = new Scanner(System.in);
- String i = input.nextLine();
- if (i.equals("1"))
- {
- System.out.println("You chose to insert a student");
- createStudent();
- }
- else if (i.equals("2"))
- {
- System.out.println("You chose to insert a book");
- createBook();
- }
- else if (i.equals("3"))
- {
- System.out.println("You chose to insert a magazine");
- createMagazine();
- }
- else if (i.equals("4"))
- {
- System.out.println("You chose to insert a loan");
- createLoan();
- }
- else if (i.equals("5"))
- {
- System.out.println("You chose to delete a loan");
- deleteLoan();
- }
- else if (i.equals("6"))
- {
- System.out.println("You chose to view all the students");
- seeStudents();
- }
- else if (i.equals("7"))
- {
- System.out.println("You chose to view all the items");
- seeItems();
- }
- else if (i.equals("8"))
- {
- System.out.println("You chose to view all the loans");
- seeLoans();
- }
- else if (i.equals("x") || i.equals("X"))
- {
- System.out.println("You chose to exit the programm");
- System.exit(0);
- }
- else
- {
- System.out.println("Error");
- }
- }
- public static void createStudent()
- {
- //Student myself = new Student ("Steve","Varitimou","poutsa@psoli.gr","E13025");
- //students.add(myself);
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the student's first name: ");
- String fn = input.nextLine();
- System.out.println("Enter the student's last name: ");
- String ln = input.nextLine();
- // Check if email has . and @ characters
- String email;
- do
- {
- System.out.println("Enter the student's email: ");
- email = input.nextLine();
- if (!(email.contains("@") && email.contains(".")))
- {
- System.out.println("Wrong entry");
- }
- }while (!(email.contains("@") && email.contains(".")));
- System.out.println("Enter the student's ID: ");
- String id = input.nextLine();
- if (students.size()>0) //To check if there is no entry at all
- {
- for (int i = 0; i < students.size(); i++)
- {
- if (students.get(i).getidFieldValue().toString().equals(id))
- {
- System.out.println("The student with this ID is already added");
- menu();
- }
- else
- {
- Student myself = new Student (fn,ln,email,id);
- students.add(myself);
- System.out.println("Student created succesfully!");
- menu();
- }
- }
- }
- else
- {
- Student myself = new Student (fn,ln,email,id);
- students.add(myself);
- System.out.println("You created the first student!");
- System.out.println("Student created succesfully!");
- menu();
- }
- }
- public static void createBook()
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the book's name: ");
- String title = input.nextLine();
- if (books.size()>0) //To check if there is no entry at all
- {
- for (int i = 0; i < books.size(); i++)
- {
- if (books.get(i).gettitleFieldValue().toString().equals(title))
- {
- System.out.println("A book with this title already exists!");
- menu();
- }
- else
- {
- System.out.println("Enter the Publisher: ");
- String pubnm = input.nextLine();
- System.out.println("Enter the Publisher's adress: ");
- String addr = input.nextLine();
- System.out.println("Enter the Publisher's country: ");
- String country = input.nextLine();
- System.out.println("Enter the Publisher's city: ");
- String city = input.nextLine();
- Publisher pub = new Publisher(pubnm, addr, country, city);
- System.out.println("Enter the ISBN: ");
- int isbn = 0;
- try {
- isbn = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the Author's first name: ");
- String fn = input.nextLine();
- System.out.println("Enter the Author's last name: ");
- String ln = input.nextLine();
- System.out.println("Enter the book's price: ");
- double pr = 0;
- try {
- pr = Double.parseDouble(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the book's year: ");
- int yr = 0;
- try {
- yr = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the book's quantity: ");
- int qnt = 0;
- try {
- qnt = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- // Check if email has . and @ characters
- String email;
- do
- {
- System.out.println("Enter the author's email: ");
- email = input.nextLine();
- if (!(email.contains("@") && email.contains(".")))
- {
- System.out.println("Wrong entry");
- }
- }while (!(email.contains("@") && email.contains(".")));
- // Check if gender is F or M
- String gndr;
- do
- {
- System.out.println("Enter the author's gender: (M/F) ");
- gndr = input.nextLine();
- if (!(gndr.equals("F") || gndr.equals("M")))
- {
- System.out.println("Wrong entry, please enter M or F");
- }
- }while (!(gndr.equals("F") || gndr.equals("M")));
- Author auth = new Author(fn, ln, email, gndr);
- Book myBook = new Book(pr, yr, qnt, pub, isbn, title, auth);
- books.add(myBook);
- items.add(myBook);
- System.out.println("Book created succesfully!");
- menu();
- }
- }
- }
- else
- {
- System.out.println("Enter the Publisher: ");
- String pubnm = input.nextLine();
- System.out.println("Enter the Publisher's adress: ");
- String addr = input.nextLine();
- System.out.println("Enter the Publisher's country: ");
- String country = input.nextLine();
- System.out.println("Enter the Publisher's city: ");
- String city = input.nextLine();
- Publisher pub = new Publisher(pubnm, addr, country, city);
- System.out.println("Enter the ISBN: ");
- int isbn = 0;
- try {
- isbn = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the Author's first name: ");
- String fn = input.nextLine();
- System.out.println("Enter the Author's last name: ");
- String ln = input.nextLine();
- System.out.println("Enter the book's price: ");
- double pr = 0;
- try {
- pr = Double.parseDouble(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the book's year: ");
- int yr = 0;
- try {
- yr = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the book's quantity: ");
- int qnt = 0;
- try {
- qnt = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- // Check if email has . and @ characters
- String email;
- do
- {
- System.out.println("Enter the author's email: ");
- email = input.nextLine();
- if (!(email.contains("@") && email.contains(".")))
- {
- System.out.println("Wrong entry");
- }
- }while (!(email.contains("@") && email.contains(".")));
- // Check if gender is F or M
- String gndr;
- do
- {
- System.out.println("Enter the author's gender: (M/F) ");
- gndr = input.nextLine();
- if (!(gndr.equals("F") || gndr.equals("M")))
- {
- System.out.println("Wrong entry, please enter M or F");
- }
- }while (!(gndr.equals("F") || gndr.equals("M")));
- Author auth = new Author(fn, ln, email, gndr);
- Book myBook = new Book(pr, yr, qnt, pub, isbn, title, auth);
- books.add(myBook);
- items.add(myBook);
- System.out.println("You created the first book!");
- System.out.println("Book created succesfully!");
- menu();
- }
- }
- public static void createMagazine()
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the Magazine's name: ");
- String title = input.nextLine();
- if (magazines.size()>0) //To check if there is no entry at all
- {
- for (int i = 0; i < magazines.size(); i++)
- {
- if (magazines.get(i).gettitleFieldValue().toString().equals(title))
- {
- System.out.println("A magazine with this title already exists");
- menu();
- }
- else
- {
- System.out.println("Enter the Publisher: ");
- String pubnm = input.nextLine();
- System.out.println("Enter the Publisher's adress: ");
- String addr = input.nextLine();
- System.out.println("Enter the Publisher's country: ");
- String country = input.nextLine();
- System.out.println("Enter the Publisher's city: ");
- String city = input.nextLine();
- Publisher pub = new Publisher(pubnm, addr, country, city);
- System.out.println("Enter the magazine's price: ");
- double pr = 0;
- try {
- pr = Double.parseDouble(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the magazine's year: ");
- int yr = 0;
- try {
- yr = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the magazine's issue: ");
- int issue = 0;
- try {
- issue = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the magazine's quantity: ");
- int qnt = 0;
- try {
- qnt = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- Magazine myMagazine = new Magazine(pr, yr, qnt, pub, issue, title);
- magazines.add(myMagazine);
- items.add(myMagazine);
- System.out.println("Magazine created succesfully!");
- menu();
- }
- }
- }
- else
- {
- System.out.println("Enter the Publisher: ");
- String pubnm = input.nextLine();
- System.out.println("Enter the Publisher's adress: ");
- String addr = input.nextLine();
- System.out.println("Enter the Publisher's country: ");
- String country = input.nextLine();
- System.out.println("Enter the Publisher's city: ");
- String city = input.nextLine();
- Publisher pub = new Publisher(pubnm, addr, country, city);
- System.out.println("Enter the magazine's price: ");
- double pr = 0;
- try {
- pr = Double.parseDouble(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the magazine's year: ");
- int yr = 0;
- try {
- yr = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the magazine's issue: ");
- int issue = 0;
- try {
- issue = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- System.out.println("Enter the magazine's quantity: ");
- int qnt = 0;
- try {
- qnt = Integer.parseInt(input.nextLine());
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- Magazine myMagazine = new Magazine(pr, yr, qnt, pub, issue, title);
- magazines.add(myMagazine);
- items.add(myMagazine);
- System.out.println("You created the first magazine!");
- System.out.println("Magazine created succesfully!");
- menu();
- }
- }
- public static void createLoan()
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the student's ID: ");
- String id = input.nextLine();
- if (students.size()>0) //To check if there is no entry at all
- {
- for (int i = 0; i < students.size(); i++)
- {
- if (students.get(i).getidFieldValue().toString().equals(id))
- {
- System.out.println("The student with this ID exists");
- Student stu = students.get(i);
- System.out.println("Enter the Book's or Magazine's title: ");
- String title = input.nextLine();
- if (items.size()>0) //To check if there is no entry at all
- {
- for (int y = 0; y < items.size(); y++)
- {
- if (items.get(y).gettitleFieldValue().toString().equals(title))
- {
- System.out.println("The title exists");
- Item itm = items.get(y);
- if (itm.quantityFieldValue > 0)
- {
- int x = itm.quantityFieldValue;
- x = x-1;
- itm.setquantityFieldValue(x);
- Loan myLoan = new Loan(stu, itm);
- loans.add(myLoan);
- System.out.println("New loan added");
- menu();
- }
- else
- {
- System.out.println("But the quantity is zero");
- menu();
- }
- }
- }
- System.out.println("There is no title with this name");
- menu();
- }
- else
- {
- System.out.println("There are no Items, please insert items in order to loan");
- menu();
- }
- }
- }
- System.out.println("There is no student with this ID");
- menu();
- }
- else
- {
- System.out.println("There are no students, please insert students to provide a loan");
- menu();
- }
- }
- public static void deleteLoan()
- {
- if (loans.size()>0) //To check if there is no entry at all
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter time of loan you want to delete MM/dd/yyyy hh:mm");
- String time = input.nextLine();
- for (int i = 0; i < loans.size(); i++)
- {
- if (loans.get(i).gettimestampFieldValue().toString().equals(time))
- {
- loans.remove(i);
- System.out.println("A loan was deleted");
- menu();
- }
- }
- System.out.println("No loan was found that time");
- menu();
- }
- else
- {
- System.out.println("The are no Loans");
- menu();
- }
- }
- public static void seeStudents()
- {
- if (students.size()>0) //To check if there is no entry at all
- {
- for (int i = 0; i < students.size(); i++)
- {
- String x = students.get(i).toString();
- System.out.println(x);
- }
- menu();
- }
- else
- {
- System.out.println("There are no students");
- menu();
- }
- }
- public static void seeItems()
- {
- if (items.size()>0) //To check if there is no entry at all
- {
- for (int i = 0; i < items.size(); i++)
- {
- String x = items.get(i).toString();
- System.out.println(x);
- }
- menu();
- }
- else
- {
- System.out.println("There are no items");
- menu();
- }
- }
- public static void seeLoans()
- {
- if (loans.size()>0) //To check if there is no entry at all
- {
- for (int i = 0; i < loans.size(); i++)
- {
- String x = loans.get(i).toString();
- System.out.println(x);
- }
- menu();
- }
- else
- {
- System.out.println("There are no loans");
- menu();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement