基本功能是实现图书管理员的上架下架, 学生的借书还书,技术含量越高越好,,希望用到多线程
有追加悬赏, O(∩_∩)O~
用java写一个控制台下实现的图书借阅
答案:1 悬赏:70 手机版
解决时间 2021-04-21 11:14
- 提问者网友:酱爆肉
- 2021-04-20 10:32
最佳答案
- 五星知识达人网友:旧脸谱
- 2021-04-20 11:44
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Test {
List<String> myBooks = new ArrayList<String>();
private String readKey() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String keyValue = "";
try {
keyValue = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return keyValue;
}
private String getAllBookNames() {
String bookNames="";
for(int i=0;i<myBooks.size();i++){
bookNames=bookNames+"<"+myBooks.get(i)+">";
}
return bookNames;
}
private void saveMyBook() {
myBooks.add(this.readKey());
System.out.println("入库成功");
}
private void delMyBook() {
myBooks.remove(this.readKey());
System.out.println("删书成功");
}
public static void main(String[] args) {
Test test=new Test();
test.myBooks.add("测试书");
String state;
System.out.println("--欢迎--");
while(true){
System.out.println("*****************************");
System.out.println("1入库;2删书;3退出;");
state=test.readKey();
if(state.equals("1")){
System.out.println("要存储的书籍名称:");
test.saveMyBook();
System.out.println("现有书籍:"+test.getAllBookNames());
}else if(state.equals("2")){
System.out.println("要删除的书籍名称:");
test.delMyBook();
System.out.println("现有书籍:"+test.getAllBookNames());
}else if(state.equals("3")){
break;
}else{
}
}
System.out.println("--再见--");
}
}
import java.util.ArrayList;
import java.util.List;
public class Test {
List<String> myBooks = new ArrayList<String>();
private String readKey() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String keyValue = "";
try {
keyValue = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return keyValue;
}
private String getAllBookNames() {
String bookNames="";
for(int i=0;i<myBooks.size();i++){
bookNames=bookNames+"<"+myBooks.get(i)+">";
}
return bookNames;
}
private void saveMyBook() {
myBooks.add(this.readKey());
System.out.println("入库成功");
}
private void delMyBook() {
myBooks.remove(this.readKey());
System.out.println("删书成功");
}
public static void main(String[] args) {
Test test=new Test();
test.myBooks.add("测试书");
String state;
System.out.println("--欢迎--");
while(true){
System.out.println("*****************************");
System.out.println("1入库;2删书;3退出;");
state=test.readKey();
if(state.equals("1")){
System.out.println("要存储的书籍名称:");
test.saveMyBook();
System.out.println("现有书籍:"+test.getAllBookNames());
}else if(state.equals("2")){
System.out.println("要删除的书籍名称:");
test.delMyBook();
System.out.println("现有书籍:"+test.getAllBookNames());
}else if(state.equals("3")){
break;
}else{
}
}
System.out.println("--再见--");
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯