In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "java single linked list how to achieve book management system". In daily operation, I believe that many people have doubts about how to achieve book management system with java single linked list. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to achieve book management system with java single linked list". Next, please follow the editor to study!
Book management system functions:
1)。 Add a book
2)。 Delete a book
3)。 View Books
4)。 Modify a book
5)。 Modify sorting method
6)。 Fuzzy query
7)。 Exit the program
Code implementation:
Book class
Package com.bookmanagement.book;public class Book {/ / Book public String no; public String name; public int price; public String type; public Book next; public Book (String Bno,String Bname,int Bprive,String Btype) {this.no=Bno; this.name=Bname; this.price=Bprive; this.type=Btype;} public Book () {} / / toString method @ Override public String toString () {return "Bookno=" + no + ", Bookname=" + name + ", Bookprice=" + price + ", Booktype=" + type }}
1)。 Add a book
Package com.bookmanagement.function;import java.util.Scanner;import com.bookmanagement.book.*;public class AddBook {static Scanner input = new Scanner (System.in); public static void addbook () {System.out.println ("Please enter Book number:"); String no = input.next (); System.out.println ("Please enter Book name:"); String name = input.next (); System.out.println ("Please enter Book Price:"); int price = input.nextInt () System.out.println ("Please enter book type:"); String type = input.next (); Book bo = new Book (no,name,price,type); add (bo);} public static void add (Book bo) {Book temp = Test.head;// assign the header node to an auxiliary class boolean falg = false; while (true) {if (temp.next = = null) {/ / determine whether the linked list reaches the last break } if (Test.stroing% 2 = = 1) {/ / determine whether the display order if (temp.next.no.compareToIgnoreCase (bo.no) 0) {/ / find a suitable location to insert the node / / skip the header node break;} else if (temp.next.no.compareToIgnoreCase (bo.no) = = 0) {falg = true; break;}} / / the node moves back temp = temp.next } if (falg) {/ / determine whether to enter the same number System.out.println (the data number of "insert" + bo.no+ "already exists");} else {bo.next = temp.next; temp.next = bo;}
2)。 Delete a book
Package com.bookmanagement.function;import java.util.Scanner;import com.bookmanagement.book.*;public class DropBook {static Scanner input = new Scanner (System.in); public static void dropbook () {System.out.println ("Please enter the number of the book to be deleted:"); String no = input.next (); Book temp = Test.head; boolean falg = false; while (true) {if (temp.next = = null) {/ / determine whether the linked list reaches the last break } if (temp.next.no.compareToIgnoreCase (no) = = 0) {falg = true; break;} temp = temp.next;//temp displacement} if (falg) {temp.next=temp.next.next / / find the temp.nextfield to point to the deleted number and let the next next overwrite / / if the next nextfield points to null, then the temp.next field points to empty System.out.println ("deleted successfully");} else {System.out.println ("book not found");}
3)。 View Books
Package com.bookmanagement.function;import com.bookmanagement.book.*;public class ShowBook {public static void showbook () {if (Test.head.next = = null) {System.out.println ("No book data"); return;} Book temp = Test.head.next;// output header node next node int sum=0; while (true) {if (temp = = null) {break;} System.out.println (temp); sum++; temp = temp.next / / temp displacement} System.out.println ("Total number of books:" + sum);}}
4)。 Modify a book
Package com.bookmanagement.function;import java.util.Scanner;import com.bookmanagement.book.*;public class Modify {static Scanner input = new Scanner (System.in); public static void modidy () {System.out.println ("Please enter the number of the book to be modified:"); String no = input.next (); Book temp = Test.head; boolean ts = false; while (true) {if (temp.next = = null) {break } if (temp.next.no.compareToIgnoreCase (no) = = 0) {ts = true; break;} temp = temp.next;} if (ts) {System.out.println ("modify: 1. Name 2. Number 3. Price 4. Type "); int falg = input.nextInt (); switch (falg) {case 1: System.out.println (" Please enter the name to be modified: "); String name = input.next (); temp.next.name = name; break; case 2: System.out.println (" Please enter the number to be modified: "); String Mno = input.next (); temp.next.no = Mno; Book change = temp.next Temp.next=temp.next.next; AddBook.add (change); / / re-call add method break; case 3: System.out.println ("Please enter the price to be modified:"); int prive = input.nextInt (); temp.next.price = prive; break; case 4: System.out.println ("Please enter the type to be modified:"); String type= input.next () Temp.next.type = type; break; default:System.out.println ("typed incorrectly"); break;}} else {System.out.println ("book not found");}
5)。 Modify sorting method
Package com.bookmanagement.function;import java.util.Scanner;import com.bookmanagement.book.*;public class Flash {static Scanner input = new Scanner (System.in); public static void flashbook () {Book everList = new Book ("", 0, "); Book temp = Test.head.next;// assigns values with data to the helper class Book next = null If (temp.next = = null) {/ / list only one data does not need to be sorted System.out.println ("linked list has only one data without reverse order"); return;} while (temp! = null) {next = temp.next; temp.next = temp; temp = next;} Test.head.next = everList.next If (Test.stroing%2==1) {System.out.println ("modify to descending");} else {System.out.println ("modify to ascending");}
6)。 Fuzzy query
Package com.bookmanagement.function;import com.bookmanagement.book.*;import java.util.Scanner;public class Detailed {static Scanner input = new Scanner (System.in); public static void detailed () {System.out.println ("function: fuzzy query"); detalied1 ();} public static void detalied1 () {System.out.println ("enter the data you need to find: 1. Book title 2. Number 3. Price 4. Type "); int falg = input.nextInt (); switch (falg) {case 1: DetaBookName (); break; case 2: DetaBookNo (); break; case 3: DetaBookPrice (); break; case 4: DetaBookType (); break; default: break;}} public static void DetaBookName () {System.out.println (" Please enter fuzzy title: "); String name = input.next (); Book temp = Test.head; boolean falg = false If (Test.head.next = = null) {System.out.println ("No book information"); return;} while (true) {if (temp.next = = null) {break;} if (temp.next.name.indexOf (name) = = 0) {System.out.println (temp.next); falg = true;} temp = temp.next } if (! falg) {System.out.println ("No book information found");}} public static void DetaBookNo () {System.out.println ("Please enter fuzzy number:"); String no = input.next (); Book temp = Test.head; boolean falg = false; if (Test.head.next = = null) {System.out.println ("No book information"); return } while (true) {if (temp.next = = null) {break;} if (temp.next.no.indexOf (no) = = 0) {System.out.println (temp.next); falg = true;} temp = temp.next;} if (! falg) {System.out.println ("this book information not found");} static int price Public static void DetaBookPrice () {System.out.print ("input symbol: (>, =,": GreaterPrice (); break; case "=": GreaterEqualePrice (); break; case "
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.