用Java写一个简单图书管理系统,不连接数据库

weixin_41091324 2017-11-22 10:01:08
本人初学者,不太会,求教!
...全文
1844 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
superliug 2019-08-07
  • 打赏
  • 举报
回复
可以私聊我,免费做
无涯子Gary 2018-01-08
  • 打赏
  • 举报
回复
自己的作业,自己写去
chengshou2106 2018-01-06
  • 打赏
  • 举报
回复
百度一下你会找到一大堆
Yang_Fan3313 2018-01-06
  • 打赏
  • 举报
回复
怎样使用JDBC? 1.加载驱动 class.forName(”com.mysql.jdbc.Driver”); 2.建立连接 Connection con = DriverManager.getConnection(url,userName,PW); 3.执行语句 有变量: PrepareStatement ps = con.getprepareStatement(“?变量”); 无变量: Statement ps = com.preparedStatement(“具体的SQL语句”);
不会VS 2017-12-27
  • 打赏
  • 举报
回复
菜单部分: import java.util.Scanner; public class Menu { int Min = 1; int Max = 3; public void getMenu(){ System.out.println("1、显示/2、输入/3、查找"); } public void getFindMenu(){ System.out.println("1、编号/2、书名/3、作者"); } public int setMenu(){ System.out.println("输入序号:"); Scanner reader = new Scanner(System.in); int num = reader.nextInt(); if(num >= Min || num <= Max) return num; else return -1; } } 重点的管理部分: 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("请输入编号"); Find(reader.next(), 0); break; case 2: System.out.println("请输入书名"); Find(reader.next(), 1); break; case 3: System.out.println("请输入作者"); 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 "没有找到"; } public String message(){ Scanner reader = new Scanner(System.in); String str = ""; String s = ""; System.out.println("请输入编号"); str = reader.next(); if(findNum(str,0).compareTo("没有找到") != 0){ System.out.println("此编号存在输入错误"); return "@@!!"; } s += str + "#"; System.out.println("请输入书名"); str = reader.next(); s += str + "#"; System.out.println("请输入作者"); 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; } } 主函数部分: 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("输入有误"); break; } } } }
chengshou2106 2017-12-25
  • 打赏
  • 举报
回复
百度以下很多项目,不过还是建议你看看就行自己动手写一下试一试
加飞猫 2017-12-24
  • 打赏
  • 举报
回复
如果不用连数据库,可否读取本地的文本文件获取用户名和密码呢
今夜明珠色 2017-12-22
  • 打赏
  • 举报
回复
报价吧
Adoxhh 2017-12-20
  • 打赏
  • 举报
回复
我有一个之前写好的,
帅帅蛟 2017-12-20
  • 打赏
  • 举报
回复
这个应该挺简单的吧,网上搜吧!挺多的
钢琴上的代码 2017-12-18
  • 打赏
  • 举报
回复
碰到流,集合就蒙了...
danielinbiti 2017-11-29
  • 打赏
  • 举报
回复
网上下一个吧,很多的
shen_wei 2017-11-29
  • 打赏
  • 举报
回复
度娘搜索下就有了。。。。
  • 打赏
  • 举报
回复
1000,我帮你写,愿意的话发个私信
shijies 2017-11-28
  • 打赏
  • 举报
回复
用xml文件存储数据
「已注销」 2017-11-27
  • 打赏
  • 举报
回复
accp的吧
一个治疗术 2017-11-27
  • 打赏
  • 举报
回复
......
饺克力克 2017-11-27
  • 打赏
  • 举报
回复
个人作业请自己完成
一缕清风007 2017-11-23
  • 打赏
  • 举报
回复
不要数据库就把数据存硬盘上吧。。对象流。。
聪头 2017-11-23
  • 打赏
  • 举报
回复
不连数据库就是静态页面了
加载更多回复(7)

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧