Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. import javax.print.DocFlavor.INPUT_STREAM;
  4.  
  5. import java.awt.im.spi.InputMethod;
  6. import java.lang.reflect.Array;
  7. import java.util.ArrayList;
  8. public class Management
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         menu();
  13.     }
  14.    
  15.     static ArrayList<Student> students = new ArrayList<Student>();
  16.     static ArrayList<Book> books = new ArrayList<Book>();
  17.     static ArrayList<Magazine> magazines = new ArrayList<Magazine>();
  18.     static ArrayList<Item> items = new ArrayList<Item>();
  19.     static ArrayList<Loan> loans = new ArrayList<Loan>();
  20.        
  21.     public static void menu()
  22.         {
  23.                 System.out.println(
  24.                         "[+] To Insert New Student Press: 1"+
  25.                         "\n[+] To Insert New Book Press: 2"+
  26.                         "\n[+] To Insert New Magazine Press: 3"+
  27.                         "\n[+] To Insert New Loan Press: 4"+
  28.                         "\n[+] To Delete Loan Press: 5"+
  29.                         "\n[+] To Print Students Press: 6"+
  30.                         "\n[+] To Print Books and Magazines Press: 7"+
  31.                         "\n[+] To Print Loans Press: 8"+
  32.                         "\n[+] For Exit Press: x or X"+
  33.                         "\n[>] Insert Choice: ");
  34.                
  35.                 Scanner input = new Scanner(System.in);
  36.                 String i = input.nextLine();
  37.                 if (i.equals("1"))
  38.                 {
  39.                     System.out.println("You chose to insert a student");
  40.                     createStudent();
  41.                 }
  42.                 else if (i.equals("2"))
  43.                 {
  44.                     System.out.println("You chose to insert a book");
  45.                     createBook();
  46.                 }
  47.                 else if (i.equals("3"))
  48.                 {
  49.                     System.out.println("You chose to insert a magazine");
  50.                     createMagazine();
  51.                 }
  52.                 else if (i.equals("4"))
  53.                 {
  54.                     System.out.println("You chose to insert a loan");
  55.                     createLoan();
  56.                 }
  57.                 else if (i.equals("5"))
  58.                 {
  59.                     System.out.println("You chose to delete a loan");
  60.                     deleteLoan();
  61.                 }
  62.                 else if (i.equals("6"))
  63.                 {
  64.                     System.out.println("You chose to view all the students");
  65.                     seeStudents();
  66.                 }
  67.                 else if (i.equals("7"))
  68.                 {
  69.                     System.out.println("You chose to view all the items");
  70.                     seeItems();
  71.                 }
  72.                 else if (i.equals("8"))
  73.                 {
  74.                     System.out.println("You chose to view all the loans");
  75.                     seeLoans();
  76.                 }
  77.                 else if (i.equals("x") || i.equals("X"))
  78.                 {
  79.                     System.out.println("You chose to exit the programm");
  80.                     System.exit(0);
  81.                 }
  82.                 else
  83.                 {
  84.                     System.out.println("Error");
  85.                 }
  86.  
  87.         }
  88.     public static void createStudent()
  89.     {
  90.         //Student myself = new Student ("Steve","Varitimou","poutsa@psoli.gr","E13025");
  91.         //students.add(myself);
  92.         Scanner input = new Scanner(System.in);
  93.         System.out.println("Enter the student's first name: ");
  94.         String fn = input.nextLine();
  95.         System.out.println("Enter the student's last name: ");
  96.         String ln = input.nextLine();
  97.        
  98.         // Check if email has . and @ characters
  99.         String email;
  100.         do
  101.         {
  102.         System.out.println("Enter the student's email: ");
  103.         email = input.nextLine();
  104.         if (!(email.contains("@") && email.contains(".")))
  105.         {
  106.             System.out.println("Wrong entry");
  107.         }
  108.        
  109.         }while (!(email.contains("@") && email.contains(".")));
  110.        
  111.         System.out.println("Enter the student's ID: ");
  112.         String id = input.nextLine();
  113.        
  114.         if (students.size()>0) //To check if there is no entry at all
  115.         {
  116.             for (int i = 0; i < students.size(); i++)
  117.             {
  118.                 if (students.get(i).getidFieldValue().toString().equals(id))
  119.                 {
  120.                     System.out.println("The student with this ID is already added");
  121.                     menu();
  122.                 }
  123.                 else
  124.                 {
  125.                     Student myself = new Student (fn,ln,email,id);
  126.                     students.add(myself);
  127.                     System.out.println("Student created succesfully!");
  128.                     menu();
  129.                 }
  130.             }
  131.         }
  132.         else
  133.         {
  134.             Student myself = new Student (fn,ln,email,id);
  135.             students.add(myself);
  136.             System.out.println("You created the first student!");
  137.             System.out.println("Student created succesfully!");
  138.             menu();
  139.         }
  140.     }
  141.     public static void createBook()
  142.     {
  143.         Scanner input = new Scanner(System.in);
  144.         System.out.println("Enter the book's name: ");
  145.         String title = input.nextLine();
  146.         if (books.size()>0) //To check if there is no entry at all
  147.         {
  148.             for (int i = 0; i < books.size(); i++)
  149.             {
  150.                 if (books.get(i).gettitleFieldValue().toString().equals(title))
  151.                 {
  152.                     System.out.println("A book with this title already exists!");
  153.                     menu();
  154.                 }
  155.                 else
  156.                 {
  157.                     System.out.println("Enter the Publisher: ");
  158.                     String pubnm = input.nextLine();
  159.                     System.out.println("Enter the Publisher's adress: ");
  160.                     String addr = input.nextLine();
  161.                     System.out.println("Enter the Publisher's country: ");
  162.                     String country = input.nextLine();
  163.                     System.out.println("Enter the Publisher's city: ");
  164.                     String city = input.nextLine();
  165.                     Publisher pub = new Publisher(pubnm, addr, country, city);
  166.                     System.out.println("Enter the ISBN: ");
  167.                     int isbn = 0;
  168.                     try {
  169.                         isbn = Integer.parseInt(input.nextLine());
  170.                     } catch (NumberFormatException e) {
  171.                         e.printStackTrace();
  172.                     }
  173.                     System.out.println("Enter the Author's first name: ");
  174.                     String fn = input.nextLine();
  175.                     System.out.println("Enter the Author's last name: ");
  176.                     String ln = input.nextLine();
  177.                     System.out.println("Enter the book's price: ");
  178.                     double pr = 0;
  179.                     try {
  180.                         pr = Double.parseDouble(input.nextLine());
  181.                     } catch (NumberFormatException e) {
  182.                         e.printStackTrace();
  183.                     }
  184.                     System.out.println("Enter the book's year: ");
  185.                     int yr = 0;
  186.                     try {
  187.                         yr = Integer.parseInt(input.nextLine());
  188.                     } catch (NumberFormatException e) {
  189.                         e.printStackTrace();
  190.                     }
  191.                     System.out.println("Enter the book's quantity: ");
  192.                     int qnt = 0;
  193.                     try {
  194.                         qnt = Integer.parseInt(input.nextLine());
  195.                     } catch (NumberFormatException e) {
  196.                         e.printStackTrace();
  197.                     }
  198.                     // Check if email has . and @ characters
  199.                     String email;
  200.                     do
  201.                     {
  202.                         System.out.println("Enter the author's email: ");
  203.                         email = input.nextLine();
  204.                         if (!(email.contains("@") && email.contains(".")))
  205.                         {
  206.                             System.out.println("Wrong entry");
  207.                         }
  208.                     }while (!(email.contains("@") && email.contains(".")));
  209.                     // Check if gender is F or M
  210.                     String gndr;
  211.                     do
  212.                     {
  213.                         System.out.println("Enter the author's gender: (M/F) ");
  214.                         gndr = input.nextLine();
  215.                         if (!(gndr.equals("F") || gndr.equals("M")))
  216.                             {
  217.                                 System.out.println("Wrong entry, please enter M or F");
  218.                             }
  219.                     }while (!(gndr.equals("F") || gndr.equals("M")));
  220.                     Author auth = new Author(fn, ln, email, gndr);
  221.                     Book myBook = new Book(pr, yr, qnt, pub, isbn, title, auth);
  222.                     books.add(myBook);
  223.                     items.add(myBook);
  224.                     System.out.println("Book created succesfully!");
  225.                     menu();
  226.                    
  227.                 }
  228.             }
  229.         }
  230.         else
  231.         {
  232.             System.out.println("Enter the Publisher: ");
  233.             String pubnm = input.nextLine();
  234.             System.out.println("Enter the Publisher's adress: ");
  235.             String addr = input.nextLine();
  236.             System.out.println("Enter the Publisher's country: ");
  237.             String country = input.nextLine();
  238.             System.out.println("Enter the Publisher's city: ");
  239.             String city = input.nextLine();
  240.             Publisher pub = new Publisher(pubnm, addr, country, city);
  241.             System.out.println("Enter the ISBN: ");
  242.             int isbn = 0;
  243.             try {
  244.                 isbn = Integer.parseInt(input.nextLine());
  245.             } catch (NumberFormatException e) {
  246.                 e.printStackTrace();
  247.             }
  248.             System.out.println("Enter the Author's first name: ");
  249.             String fn = input.nextLine();
  250.             System.out.println("Enter the Author's last name: ");
  251.             String ln = input.nextLine();
  252.             System.out.println("Enter the book's price: ");
  253.             double pr = 0;
  254.             try {
  255.                 pr = Double.parseDouble(input.nextLine());
  256.             } catch (NumberFormatException e) {
  257.                 e.printStackTrace();
  258.             }
  259.             System.out.println("Enter the book's year: ");
  260.             int yr = 0;
  261.             try {
  262.                 yr = Integer.parseInt(input.nextLine());
  263.             } catch (NumberFormatException e) {
  264.                 e.printStackTrace();
  265.             }
  266.             System.out.println("Enter the book's quantity: ");
  267.             int qnt = 0;
  268.             try {
  269.                 qnt = Integer.parseInt(input.nextLine());
  270.             } catch (NumberFormatException e) {
  271.                 e.printStackTrace();
  272.             }
  273.             // Check if email has . and @ characters
  274.             String email;
  275.             do
  276.             {
  277.                 System.out.println("Enter the author's email: ");
  278.                 email = input.nextLine();
  279.                 if (!(email.contains("@") && email.contains(".")))
  280.                 {
  281.                     System.out.println("Wrong entry");
  282.                 }
  283.             }while (!(email.contains("@") && email.contains(".")));
  284.             // Check if gender is F or M
  285.             String gndr;
  286.             do
  287.             {
  288.                 System.out.println("Enter the author's gender: (M/F) ");
  289.                 gndr = input.nextLine();
  290.                 if (!(gndr.equals("F") || gndr.equals("M")))
  291.                     {
  292.                         System.out.println("Wrong entry, please enter M or F");
  293.                     }
  294.             }while (!(gndr.equals("F") || gndr.equals("M")));
  295.             Author auth = new Author(fn, ln, email, gndr);
  296.             Book myBook = new Book(pr, yr, qnt, pub, isbn, title, auth);
  297.             books.add(myBook);
  298.             items.add(myBook);
  299.             System.out.println("You created the first book!");
  300.             System.out.println("Book created succesfully!");
  301.             menu();
  302.         }
  303.    
  304.    
  305.    
  306.     }
  307.     public static void createMagazine()
  308.  
  309.     {
  310.         Scanner input = new Scanner(System.in);
  311.         System.out.println("Enter the Magazine's name: ");
  312.         String title = input.nextLine();
  313.         if (magazines.size()>0) //To check if there is no entry at all
  314.         {
  315.             for (int i = 0; i < magazines.size(); i++)
  316.             {
  317.                 if (magazines.get(i).gettitleFieldValue().toString().equals(title))
  318.                 {
  319.                     System.out.println("A magazine with this title already exists");
  320.                     menu();
  321.                 }
  322.                 else
  323.                 {
  324.                     System.out.println("Enter the Publisher: ");
  325.                     String pubnm = input.nextLine();
  326.                     System.out.println("Enter the Publisher's adress: ");
  327.                     String addr = input.nextLine();
  328.                     System.out.println("Enter the Publisher's country: ");
  329.                     String country = input.nextLine();
  330.                     System.out.println("Enter the Publisher's city: ");
  331.                     String city = input.nextLine();
  332.                     Publisher pub = new Publisher(pubnm, addr, country, city);
  333.                     System.out.println("Enter the magazine's price: ");
  334.                     double pr = 0;
  335.                     try {
  336.                        pr = Double.parseDouble(input.nextLine());
  337.                     } catch (NumberFormatException e) {
  338.                         e.printStackTrace();
  339.                     }
  340.                     System.out.println("Enter the magazine's year: ");
  341.                     int yr = 0;
  342.                     try {
  343.                         yr = Integer.parseInt(input.nextLine());
  344.                     } catch (NumberFormatException e) {
  345.                         e.printStackTrace();
  346.                     }
  347.                     System.out.println("Enter the magazine's issue: ");
  348.                     int issue = 0;
  349.                     try {
  350.                         issue = Integer.parseInt(input.nextLine());
  351.                     } catch (NumberFormatException e) {
  352.                         e.printStackTrace();
  353.                     }
  354.                     System.out.println("Enter the magazine's quantity: ");
  355.                     int qnt = 0;
  356.                     try {
  357.                         qnt = Integer.parseInt(input.nextLine());
  358.                     } catch (NumberFormatException e) {
  359.                         e.printStackTrace();
  360.                     }
  361.                    
  362.                     Magazine myMagazine = new Magazine(pr, yr, qnt, pub, issue, title);
  363.                     magazines.add(myMagazine);
  364.                     items.add(myMagazine);
  365.                     System.out.println("Magazine created succesfully!");
  366.                     menu();
  367.                    
  368.                 }
  369.             }
  370.         }
  371.         else
  372.         {
  373.             System.out.println("Enter the Publisher: ");
  374.             String pubnm = input.nextLine();
  375.             System.out.println("Enter the Publisher's adress: ");
  376.             String addr = input.nextLine();
  377.             System.out.println("Enter the Publisher's country: ");
  378.             String country = input.nextLine();
  379.             System.out.println("Enter the Publisher's city: ");
  380.             String city = input.nextLine();
  381.             Publisher pub = new Publisher(pubnm, addr, country, city);
  382.             System.out.println("Enter the magazine's price: ");
  383.             double pr = 0;
  384.             try {
  385.                pr = Double.parseDouble(input.nextLine());
  386.             } catch (NumberFormatException e) {
  387.                 e.printStackTrace();
  388.             }
  389.             System.out.println("Enter the magazine's year: ");
  390.             int yr = 0;
  391.             try {
  392.                 yr = Integer.parseInt(input.nextLine());
  393.             } catch (NumberFormatException e) {
  394.                 e.printStackTrace();
  395.             }
  396.             System.out.println("Enter the magazine's issue: ");
  397.             int issue = 0;
  398.             try {
  399.                 issue = Integer.parseInt(input.nextLine());
  400.             } catch (NumberFormatException e) {
  401.                 e.printStackTrace();
  402.             }
  403.             System.out.println("Enter the magazine's quantity: ");
  404.             int qnt = 0;
  405.             try {
  406.                 qnt = Integer.parseInt(input.nextLine());
  407.             } catch (NumberFormatException e) {
  408.                 e.printStackTrace();
  409.             }
  410.            
  411.             Magazine myMagazine = new Magazine(pr, yr, qnt, pub, issue, title);
  412.             magazines.add(myMagazine);
  413.             items.add(myMagazine);
  414.             System.out.println("You created the first magazine!");
  415.             System.out.println("Magazine created succesfully!");
  416.             menu();
  417.         }
  418.    
  419.    
  420.     }
  421.     public static void createLoan()
  422.     {
  423.         Scanner input = new Scanner(System.in);
  424.         System.out.println("Enter the student's ID: ");
  425.         String id = input.nextLine();
  426.         if (students.size()>0) //To check if there is no entry at all
  427.         {
  428.             for (int i = 0; i < students.size(); i++)
  429.             {
  430.                 if (students.get(i).getidFieldValue().toString().equals(id))
  431.                 {
  432.                     System.out.println("The student with this ID exists");
  433.                     Student stu = students.get(i);
  434.  
  435.                     System.out.println("Enter the Book's or Magazine's title: ");
  436.                     String title = input.nextLine();
  437.                     if (items.size()>0) //To check if there is no entry at all
  438.                     {  
  439.                         for (int y = 0; y < items.size(); y++)
  440.                         {
  441.                             if (items.get(y).gettitleFieldValue().toString().equals(title))
  442.                             {
  443.                                 System.out.println("The title exists");
  444.                                 Item itm = items.get(y);
  445.                                 if (itm.quantityFieldValue > 0)
  446.                                 {
  447.                                     int x = itm.quantityFieldValue;
  448.                                     x = x-1;
  449.                                     itm.setquantityFieldValue(x);
  450.                                     Loan myLoan = new Loan(stu, itm);
  451.                                     loans.add(myLoan);
  452.                                     System.out.println("New loan added");
  453.                                     menu();
  454.                                 }
  455.                                 else
  456.                                 {
  457.                                     System.out.println("But the quantity is zero");
  458.                                     menu();
  459.                                 }
  460.                             }
  461.                         }
  462.                         System.out.println("There is no title with this name");
  463.                         menu();
  464.                     }
  465.                     else
  466.                     {
  467.                         System.out.println("There are no Items, please insert items in order to loan");
  468.                         menu();
  469.                     }
  470.                
  471.                
  472.                 }
  473.                
  474.             }
  475.             System.out.println("There is no student with this ID");
  476.             menu();
  477.         }
  478.         else
  479.         {
  480.             System.out.println("There are no students, please insert students to provide a loan");
  481.             menu();
  482.         }
  483.        
  484.        
  485.    
  486.    
  487.        
  488. }
  489.     public static void deleteLoan()
  490.     {
  491.         if (loans.size()>0) //To check if there is no entry at all
  492.         {
  493.             Scanner input = new Scanner(System.in);
  494.             System.out.println("Enter time of loan you want to delete MM/dd/yyyy hh:mm");
  495.             String time = input.nextLine();
  496.             for (int i = 0; i < loans.size(); i++)
  497.             {
  498.                 if (loans.get(i).gettimestampFieldValue().toString().equals(time))
  499.                 {
  500.                     loans.remove(i);
  501.                     System.out.println("A loan was deleted");
  502.                     menu();
  503.                 }
  504.             }
  505.             System.out.println("No loan was found that time");
  506.             menu();
  507.         }
  508.         else
  509.         {
  510.             System.out.println("The are no Loans");
  511.             menu();
  512.         }
  513.     }
  514.     public static void seeStudents()
  515.     {
  516.         if (students.size()>0) //To check if there is no entry at all
  517.         {
  518.             for (int i = 0; i < students.size(); i++)
  519.             {
  520.                 String x = students.get(i).toString();
  521.                 System.out.println(x);
  522.             }
  523.             menu();
  524.         }
  525.         else
  526.         {
  527.             System.out.println("There are no students");
  528.             menu();
  529.         }  
  530.     }
  531.     public static void seeItems()
  532.     {
  533.         if (items.size()>0) //To check if there is no entry at all
  534.         {
  535.             for (int i = 0; i < items.size(); i++)
  536.             {
  537.                 String x = items.get(i).toString();
  538.                 System.out.println(x);
  539.             }
  540.             menu();
  541.         }
  542.         else
  543.         {
  544.             System.out.println("There are no items");
  545.             menu();
  546.         }  
  547.     }
  548.     public static void seeLoans()
  549.     {
  550.         if (loans.size()>0) //To check if there is no entry at all
  551.         {
  552.             for (int i = 0; i < loans.size(); i++)
  553.             {
  554.                 String x = loans.get(i).toString();
  555.                 System.out.println(x);
  556.             }
  557.             menu();
  558.         }
  559.         else
  560.         {
  561.             System.out.println("There are no loans");
  562.             menu();
  563.         }
  564.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement