首页 > 作文

java单链表实现书籍管理系统

更新时间:2023-04-03 22:08:44 阅读: 评论:0

本文实例为大家分享了java单链表实现书籍管理系统的具体代码,供大家参考,具体内容如下

书籍管理系统功能:

1).添加图书
2).删除图书
3).查看图书
4).修改书籍
5).修改排序方式
6).模糊查询
7).退出程序

代码实现:

book类

package com.bookmanagement.book;public class 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方法 @override public string tostring() {  return "  bookno=" + no + ",  bookname=" + name + ",  bookprice=" + price + ", booktype=" + type; }  }

1).添加图书

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("请输入书编号:");  string no = input.next();  system.out.println("请输入书名字:");  string name = input.next();  system.out.println("请输入书价格:");  int price = input.nextint();  system.out.println("请输入书类型:");  string type = input.next();  book bo = new book(no,name,price,type);  add(bo); } public static void add(book bo) {  book temp = te第一季度st.head;//把头节点赋值给一个辅助类  boolean falg = fal;  while(true) {   if(temp.next == null) {//判断链表是否到最后    break;   }   if(test.stroing %2 == 1) {//判断是否修改了显示顺序    if(temp.next.no.comparetoignoreca(bo.no)<0) {//寻找适合的位置插入节点//跳过头节点     break;    }el if(temp.next.no.comparetoignoreca(bo.no)==0){     falg = true;     break;    }   }el {    if(temp.next.no.comparetoignoreca(bo.no)>0) {//寻找适合的位置插入节点//跳过头节点     break;    }el if(temp.next.no.comparetoignoreca(bo.no)==0)井然有序造句{     falg = true;     break;    }           }   //节点后移   temp = temp.next;  }  if(falg) {//判断是否输入相同的编号   system.out.println("插入"+bo.no+"的数据编号已存在");  }el {   bo.next = temp.next;   temp.next = bo;  }   } }

2).删除图书

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("请输入需要删除图书的编号:");  string no = input.next();  book temp = test.head;  boolean falg = fal;  while(true) {   if(temp.next == null) {//判断链表是否到最后    break;   }   if(temp.next.no.comparetoignoreca(no)==0) {    falg = true;    break;   }   temp = temp.next;//temp位移  }  if(falg) {    temp.next=temp.next.next;//找到temp.next域指向删除的编号让下一个next覆盖    //如果需要删除的编号下一个next域指向的是null则temp.next域则下一个指向为空    system.out.println("删除成功");  }el {   system.out.println("没有找到该书籍");  }      }}

3).查看图书

package com.bookmanagement.function;import com.bookmanagement.book.*;public class showbook { public static void showbook() {  if(test.head.next == null) {   system.out.println("没有书籍数据");   return;  }  book temp = test.head.next;//输出头节点下一个节点  int sum=0;  while(true) {   if(temp == null) {    break;   }   system.out.println(temp);   sum++;   temp = temp.next;//temp位移  }  system.out.println("书籍总数为:"+sum);   }}

4).修改书籍

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("请输入需要修改的图书的编号:");  string no = input.next();  book temp = test.head;  boolean ts = fal;  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.no.comparetoignoreca(no)==0) {    ts = true;    break;   }   temp = temp.next;  }  if(ts) {   system.out.println("修改:1.名字 2.编号 3.价格 4.类型");   int falg = input.nextint();   switch (falg) {   ca 1:    system.out.println("请输入需要修改的名字:");    string name = input.next();    temp.next.name = name;    break;   ca 2:    system.out.println("请输入需要修改的编号:");    string mno = input.next();    temp.next.no = mno;    book change = temp.next;    temp.next=temp.next.next;    addbook.add(change);    //重新调用add方法    break;   ca 3:    system.out.println("请输入需要修改的价格:");    int prive = input.nextint();    temp.next.price = prive;    break;   ca 4:    system.out.println("请输入需要修改的类型:");    string type= input.next();    temp.next.type = type;    break;   default:system.out.println("输入有误");    break;   }  }el{   system.out.println("没有找到该书籍");  }  }}

5).修改排序方式

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;//把有数据的赋值给辅助类  book next = null;  if(temp.next == null) {//链表只有一个数据不需要排序   system.out.println("链表只有一个数据不需要逆序");   return;  }  while(temp != null) {   next = temp.next;   temp.next = everlist.next;   everlist.next = temp;   temp = next;  }  test.head.next = everlist.next;  if(test.stroing%2==1) {   system.out.println("修改为降序");  }el {   system.out.println("修改为升序");  } }}

6).模糊查询

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("功能:模糊查询");   detalied1(); } public static void detalied1() {  system.out.println("输入需要查找的数据:1.书名2.编号3.价格4.类型");  int falg = input.nextint();  switch (falg) {  ca 1:   detabookname();   break;  ca 2:   detabookno();   break;  ca 3:   detabookprice();   break;  ca 4:   detabooktype();   break;  default:   break;  } } public static void detabookname() {  system.out.println("请输入模糊书名:");  string name = input.next();  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");   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("没有找到该书籍信息");  } } public static void detabookno() {  system.out.println("请输入模糊编号:");  string no = input.next();  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");   return;  }  while(t学钢琴多少钱rue) {   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("没有找到该书籍信息");  } } static int price; public static void detabookprice() {  system.out.print("输入符号:(>,<,=,>=,<=,!=):");  string symbol = input.next();  system.out.print("输入价格:");  price = input.nextint();  system.out.println();  switch (symbol范本) {  ca ">":   greaterprice();   break;  ca "<":   lessprice();   break;  ca "=":   equalprice();   break;  ca ">=":   greaterequaleprice();   break;  ca "<=":   lesqualeprice();   break;  ca "!=":   notequale();   break;  default:system.out.println("输入错误");   break;  } } public static void greaterprice() {  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");  }  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.price>price) {    system.out.println(temp.next);    falg = true;   }   temp = temp.next;  }  if(!falg) {   system.out.println("没有书籍符合信息");  } } public static void lessprice() {  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");  }  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.price<price) {    system.out.println(temp.next);    falg = true;   }   temp = temp.next;  }  if(!falg) {   system.out.println("没有书籍符合信息");  } } public static void equalprice() {  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");  }  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.price==price) {    system.out.println(temp.next);    falg = true;   }   temp = temp.next;  }  if(!falg) {   system.out.println("没有书籍符合信息");  } } public static void greaterequaleprice() {  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");  }  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.price>=price) {    system.out.println(temp.next);    falg = true;   }   temp = temp.next;  }  if(!falg) {   system.out.println("没有书籍符合信息");  } } public static void lesqualeprice() {  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");  }  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.price<=price) {    system.out.println(temp.next);    falg = true;   }   temp = temp.next;  }  if(!falg) {   system.out.println("没有书籍符合信息");  } } public static void notequale() {  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");  }  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.price!=price) {    system.out.println(temp.next);    falg = true;   }   temp = temp.next;  }  if(!falg) {   system.out.println("没有书籍符合信息");  } } public static void detabooktype() {  system.out.println("请输入模糊类型:");  string type = input.next();  book temp = test.head;  boolean falg = fal;  if(test.head.next == null) {   system.out.println("没有书籍信息");   return;  }  while(true) {   if(temp.next == null) {    break;   }   if(temp.next.type.indexof(type)==0) {    system.out.println(temp.next);    falg = true;   }   temp = temp.next;  }  if(!falg) {   system.out.println("没有找到该书籍信息");  } } }

7).测试类

package com.bookmanagement.function;import java.util.scanner;import com.bookmanagement.book.*;public class test { static int stroing=0; public static book head = new book("","",0,"");//建立链表头 public static void main(string[] args) {  scanner input = new scanner(system.in);  system.out.println("-----欢迎进入图书管理系统-----");  boolean temp = true;  while(temp) {   system.out.println("1).添加图书");   system.out.println("2).删除图书");   system.out.println("3).查看图书");   system.out.println("4).修改书籍");   system.out.println("5).修改排序方式");   system.out.println("6).模糊查询");   system.out.println("7).退出程序");   int choo = input.nextint();   switch (choo) {   ca 1:    addbook.addbook();//添加书籍    break;   ca 2:    dropbook.dropbook();//删除书籍    break;   ca 3:    showbook.showbook();//查看书籍    break;   ca 4:    modify.modidy();//修改书籍    break;   ca 5:    stroing++;    flash.flashbook();//修改排序方式    break;   ca 6:    detailed.detailed();//模糊查询    break;   ca 7:    temp = fal;//退出程序    break;   default:system.out.println("输入错误");    break;   }  }  system.out.println("程序退出,欢迎下次使用");  input.clo(); }}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。

本文发布于:2023-04-03 22:08:43,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/180786f1050507dc6cbd51eaf7662a10.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:java单链表实现书籍管理系统.doc

本文 PDF 下载地址:java单链表实现书籍管理系统.pdf

下一篇:返回列表
标签:书籍   请输入   信息   节点
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图