A humble Java Library Management system _java

Source: Internet
Author: User

This article code for the original a simple management system, only to do functional testing. And not to improve all the necessary functions, only to do the input and output lookup, for reference only!

Menu section:

Import Java.util.Scanner;
public class Menu {
  int Min = 1;
  int Max = 3;
  public void GetMenu () {
    System.out.println ("1, Show/2, input/3, find");
  }
  public void Getfindmenu () {
    System.out.println ("1, Number/2, title/3, author");
  }
  public int SetMenu () {
    System.out.println ("Input serial Number:");
    Scanner reader = new Scanner (system.in);
    int num = Reader.nextint ();
    if (num >= Min | | | num <= Max) return
      num;
    else
      return-1;
  }
}

management component of the focus:

Import Java.io.File;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import Java.util.Scanner;

Import java.io.IOException;
    public class Book {public void Find () {Menu menu = new menu ();
    Menu.getfindmenu ();
    Scanner reader = new Scanner (system.in);
    int num = Menu.setmenu ();
      Switch (num) {case 1:SYSTEM.OUT.PRINTLN ("Please enter Number");
      Find (Reader.next (), 0);
    Break
      Case 2:SYSTEM.OUT.PRINTLN ("Please enter the title");
      Find (Reader.next (), 1);
    Break
      Case 3:SYSTEM.OUT.PRINTLN ("please input author");
      Find (Reader.next (), 2);
    Break
      } public void Find (String s,int N) {try {Scanner in = new Scanner (New File ("Res/book.txt"));
        while (In.hasnextline ()) {String str = in.nextline ();
        string[] book = Str.trim (). Split ("#");
      if (Book[n].compareto (s) = = 0) System.out.println (book[0] + "" + book[1] + "" + book[2]); } catch (FileNotFoundException e) {E.printStackTrace ();
      } public string FindNum (String s,int N) {try {Scanner in = new Scanner (New File ("Res/book.txt");
        while (In.hasnextline ()) {String str = in.nextline ();
        string[] book = Str.trim (). Split ("#");
      if (Book[n].compareto (s) = = 0) return book[n];
    } catch (FileNotFoundException e) {e.printstacktrace ();
  Return "not Found";
    Public String message () {Scanner reader = new Scanner (system.in);
    String str = "";
    String s = "";
    System.out.println ("Please enter Number");
    str = Reader.next ();
      if (FindNum (str,0). CompareTo ("not Found")!= 0) {System.out.println ("There is an input error for this number");
    return "@@!!";
    } s + + str + "#";
    System.out.println ("Please enter the title");
    str = Reader.next ();
    s + + str + "#";
    SYSTEM.OUT.PRINTLN ("Please input author");
    str = Reader.next ();
    s + + str + "#\n";
  return s;
    public void Setbook () {FileOutputStream FOP = null;
    File file; String content = Message ();  
    if (Content.compareto ("@@!!") = = 0) return;
      try {file = new file ("Res/book.txt");
      FOP = new FileOutputStream (file,true);
      byte[] contentinbytes = Content.getbytes ();
      Fop.write (contentinbytes);
      Fop.flush ();
      Fop.close ();
    System.out.println ("Done");
    catch (IOException e) {e.printstacktrace ();
        Finally {try {if (FOP!= null) {fop.close ();
      } catch (IOException e) {e.printstacktrace ();
      }} public void GetBook () {try {Scanner in = new Scanner (New File ("Res/book.txt"));
        while (In.hasnextline ()) {String str = in.nextline ();
      Splitt (str);
    } catch (FileNotFoundException e) {e.printstacktrace ();
    } public static string[] Splitt (String str) {string[] book = Str.trim (). Split ("#");
    for (int i = 0; i < book.length i++) {System.out.println (book[i]); } System.out.printlN ("\n*********************");
  return book;
 }
}

Main function Section:

public class Managebook {public
   static void Main (string[] agse) {
    Menu menu = new Menu ();
    Book book = new book ();
    while (true) {
      menu.getmenu ();
      int num = Menu.setmenu ();
      Switch (num) {case
        1:
          book.getbook ();
          break;
        Case 2:
          book.setbook ();
          break;
        Case 3:
          book.find ();
          break;
        Case-1:
          System.out.println ("incorrect input");
          Break;}}}


The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.