开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
Test.java 17.84 KB
一键复制 编辑 原始数据 按行查看 历史
wooz 提交于 2020年12月20日 12:01 +08:00 . edit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
package tes;
import java.util.Scanner;
/*用户登录 改密码
*书籍的信息管理(增加 删除 更新 查询(根据出版社查询 根据ISBN查询 根据价格范围查询 根据书名查询 根据作者查询))
*出版社管理
*用户管理
*/
public class Test {
static String[][] user = new String[10][4];
static String[][] book = new String[20][5];
static String[][] pubCom = new String[5][3]; // 出版社
public static void main(String[] args) {
init();
Scanner s = new Scanner(System.in);
System.out.println("欢迎使用XXX书籍管理系统!!!");
boolean loginSuc = true;
while (loginSuc) {
System.out.println("请输入用户名:");
String userName = s.next();
System.out.println("请输入用户密码:");
String userPwd = s.next();
if (login(userName, userPwd)) {
boolean p = true;
while (p) {
System.out.println("请输入数字进行选择:1 图书管理 2 出版社管理 3 退出系统");
int c = s.nextInt();
if (c == 1) {
// 图书管理
boolean t = true;
while (t) {
System.out.println("请输入:1.增加 2.删除 3.更新 4.查询 5.返回上一级菜单");
int k = s.nextInt();
if (k == 1) {
System.out.println("请输入图书ISBN:");
String isbn = s.next();
System.out.println("请输入书名:");
String bookName = s.next();
System.out.println("请输入价格:");
String bookPrice = s.next();
System.out.println("请输入出版社:");
String pubCom = s.next();
System.out.println("请输入作者:");
String author = s.next();
boolean b = insertBook(isbn, bookName, bookPrice, pubCom, author);
if(b){
System.out.println("添加成功!!!");
}else{
System.out.println("添加失败!!!该书已经存在!!!");
}
} else if (k == 2) {
System.out.println("请输入要删除的ISBN:");
String isbn = s.next();
boolean b = delByIsbn(isbn);
if(b){
System.out.println("删除成功!!!");
}else{
System.out.println("删除失败!!!该isbn号无效!!!");
}
} else if (k == 3) {
System.out.println("请输入ISBN号:");
String isbn = s.next();
int index = getIndexByISBN(isbn);
if(index!=-1){
System.out.println("请输入新的书名:");
String bookName = s.next();
System.out.println("请输入新的价格:");
String bookPrice = s.next();
System.out.println("请输入新的出版社:");
String pubCom = s.next();
System.out.println("请输入新的作者:");
String author = s.next();
//调用更新函数
boolean b = updateBook(index, bookName, bookPrice, pubCom, author);
if(b){
System.out.println("更新成功!!!");
}else{
System.out.println("更新失败");
}
}else{
System.out.println("该ISBN号不存在!!!");
}
} else if (k == 4) {
boolean y = true;
while (y) {
System.out.println("请输入查询种类:1.isbn 2.书名(模糊) 3.出版社 4. 作者 5. 价格范围 6.查询所有 7.返回上一级 ");
int h = s.nextInt();
if (h == 1) {
System.out.println("请输入ISBN号:");
String isbn = s.next();
searchBookByISBN(isbn);
} else if (h == 2) {
System.out.println("请输入书名:");
String bookName = s.next();
searchByBookName(bookName);
} else if (h == 3) {
System.out.print("请输入出版社前的数字进行选择:");
//打印所有的出版社
printPC();
int d = s.nextInt();
if(d>=1&& d<=getNumOfPC()){ //用户输入的数字有效
//根据输入的整数要找到对应的出版社名称
String pcName = pubCom[d-1][0];
//调用函数根据出版社名称查询
searchBookByPC(pcName);
}else{ //用户输入的数字超出范围
System.out.println("请选择正确的数字!!!");
}
} else if (h == 4) {
System.out.println("请输入作者姓名:");
String author = s.next();
searchBookByAuthor(author);
} else if (h == 5) {
System.out.println("请输入最低价格");
int min = s.nextInt();
System.out.println("请输入最高价格");
int max = s.nextInt();
searchBookByPrice(min, max);
} else if (h == 6) {
// 调用查询所有函数
searchAllBook();
} else if (h == 7) {
y = false;
} else {
System.out.println("请输入正确的数字选项!!!");
}
}
} else if (k == 5) {
t = false;
} else {
System.out.println("请输入正确的选项数字!!!");
}
}
} else if (c == 2) {
// 出版社管理
boolean t = true;
while (t) {
System.out.println("请输入:1.增加 2.删除 3.更新 4.根据出版社名称查询 5.查询所有出版社 6.返回上一级菜单");
int k = s.nextInt();
if (k == 1) {
System.out.println("请输入出版社名称:");
String pcName = s.next();
System.out.println("请输入出版社地址:");
String pcAddress = s.next();
System.out.println("请输入出版社联系人:");
String pcPerson = s.next();
// b为false表示已经存在,所以添加失败
boolean b = insertPC(pcName, pcAddress, pcPerson);
if (b) {
System.out.println("出版社添加成功");
} else {
System.out.println("出版社添加失败");
}
} else if (k == 2) {
System.out.println("请输入要删除的出版社名称:");
String pcName = s.next();
boolean b = delByPCName(pcName);
if (b) {
System.out.println("删除成功");
} else {
System.out.println("删除失败");
}
} else if (k == 3) {
// 更新出版社信息
System.out.println("请输入要更新的出版社名称:");
String pcName = s.next();
int index = searchByPCName(pcName);
//根据下标打印
printPubCom(index);
//接受用户输入新的信息(因为没有设置id,用name当主键,所以出版社名称不能改)
System.out.println("请输入要更新的地址:");
String pcAddress = s.next();
System.out.println("请输入要更新的联系人姓名:");
String pcPerson = s.next();
//调用更新函数
boolean b = updatePubCom(index, pcAddress, pcPerson);
if(b){
System.out.println("更新成功");
//更新成功后打印最新数据
printPubCom(index);
}else{
System.out.println("更新失败!!!");
}
} else if (k == 4) {
System.out.println("请输入出版社名称:");
String pcName = s.next();
int index = searchByPCName(pcName);
if (index != -1) {
System.out.println("出版社名称:" + pubCom[index][0]);
System.out.println("出版社地址:" + pubCom[index][1]);
System.out.println("出版社联系人:" + pubCom[index][2]);
} else {
System.out.println("该出版社不存在!!!");
}
} else if (k == 5) {
//查询所有出版社信息
searchAllPubCom();
} else if (k == 6) {
t = false;
}else {
System.out.println("请输入正确的选项数字!!!");
}
}
} else if (c == 3) {
// 退出系统
p = false;
loginSuc = false;
System.out.println("感谢使用本系统!!");
} else {
System.out.println("请输入正确的选项数字!!!");
}
}
} else {
System.out.println("该用户不存在或者密码错误!!!请重新登录!!!");
}
}
}
// 登录
static boolean login(String userName, String userPwd) {
boolean b = false;
for (int i = 0; i < user.length; i++) {
if (userName.equals(user[i][1]) && userPwd.equals(user[i][2])) {
b = true;
break;
}
}
return b;
}
//查询所有出版社信息
static void searchAllPubCom(){
System.out.println("出版社名称\t地址 \t联系人\t");
for (int i = 0; i < pubCom.length; i++) {
if (pubCom[i][0] != null) {
System.out.println(pubCom[i][0] + "\t" + pubCom[i][1] + "\t" + pubCom[i][2] + "\t");
}
}
}
//得到出版社的个数
static int getNumOfPC(){
int count = 0;
for(int i = 0;i<pubCom.length;i++){
if(pubCom[i][0]!=null){
count++;
}
}
return count;
}
//在用户选择出版社的时候动态输出所有出版社的信息
static void printPC(){
for(int i = 0;i<pubCom.length;i++){
if(pubCom[i][0]!= null){
System.out.print(i+1+". "+pubCom[i][0]+" ");
}
}
System.out.println();
}
// 出版社添加
static boolean insertPC(String pcName, String pcAddress, String pcPerson) {
boolean b = false;
// 如果该出版社不存在
if (searchByPCName(pcName) == -1) {
// 查找第一个null的下标
int index = getPCIndexOfFirstNull();
// 在null下标上完成添加操作
pubCom[index][0] = pcName;
pubCom[index][1] = pcAddress;
pubCom[index][2] = pcPerson;
b = true;
}
return b;
}
// 查找书籍数组中第一个null的下标
static int getBookIndexOfFirstNull() {
int index = -1;
for (int i = 0; i < book.length; i++) {
if (book[i][0] == null) {
index = i;
break;
}
}
return index;
}
// 查找出版社数组中第一个null的下标
static int getPCIndexOfFirstNull() {
int index = -1;
for (int i = 0; i < pubCom.length; i++) {
if (pubCom[i][0] == null) {
index = i;
break;
}
}
return index;
}
//判断出版社是否在图书表中有关联信息
static boolean isExistInBook(String pcName){
boolean bool = false; //默认不存在
for(int i = 0;i<book.length;i++){
if(pcName.equals(book[i][3])){
bool = true;
break;
}
}
return bool;
}
// 出版社删除
static boolean delByPCName(String pcName) {
boolean b = false;
int index = searchByPCName(pcName);
// 如果出版社存在,并且没有关联的图书数据就删除
if (index != -1) {
if(!isExistInBook(pcName)){
for(int i = index;i<pubCom.length-1;i++){
pubCom[i] = pubCom[i+1];
}
b = true;
}else{
System.out.println("该出版社有相关图书信息存在!不可以删除!如果要删除请先删除所有相关图书信息!!!");
}
}
return b;
}
// 修改某下标的出版社信息(不含出版社名称)
static boolean updatePubCom(int index , String pcAddress , String pcPerson){
boolean b = false;
pubCom[index][1] = pcAddress;
pubCom[index][2] = pcPerson;
b = true;
return b;
}
//根据下标打印出版社信息
static void printPubCom(int index){
System.out.println("出版社名称\t地址 \t联系人\t");
System.out.print(pubCom[index][0]+"\t");
System.out.print(pubCom[index][1]+"\t");
System.out.println(pubCom[index][2]+"\t");
}
// 根据出版社名称精确查询
static int searchByPCName(String pcName) {
int index = -1;
for (int i = 0; i < pubCom.length; i++) {
if (pcName.equals(pubCom[i][0])) {
index = i;
break;
}
}
return index;
}
// 书籍增加
static boolean insertBook(String isbn,String bookName , String bookPrice , String pubCom , String author) {
boolean b = false;
// 如果该书籍不存在
int i = getIndexByISBN(isbn);
if(i==-1){
//找到空位置的下标
int index = getBookIndexOfFirstNull();
//赋值
book[index][0] = isbn;
book[index][1] = bookName;
book[index][2] = bookPrice;
book[index][3] = pubCom;
book[index][4] = author;
b = true;
}
return b;
}
// 书籍删除
static boolean delByIsbn(String isbn) {
boolean b = false;
// 如果存在就删除
int index = getIndexByISBN(isbn);
if(index!=-1){
for(int i = 0;i<book[index].length;i++){
book[index][i] = null;
}
//删除成功
b = true;
}
return b;
}
// 根据下标书籍更新(此处isbn号不能更新)
static boolean updateBook(int index,String bookName , String bookPrice , String pubCom , String author){
boolean b = false;
book[index][1] = bookName;
book[index][2] = bookPrice;
book[index][3] = pubCom;
book[index][4] = author;
b = true;
return b;
}
// 查询所有图书
static void searchAllBook() {
System.out.println("ISBN\t书名 \t价格\t出版社 \t作者\t");
for (int i = 0; i < book.length; i++) {
if (book[i][0] != null) {
System.out.println(book[i][0] + "\t" + book[i][1] + "\t" + book[i][2] + "\t" + book[i][3] + "\t"
+ book[i][4] + "\t");
}
}
}
//根据isbn号查询下标,默认不存在为-1
static int getIndexByISBN(String isbn){
int index = -1;
for (int i = 0; i < book.length; i++) {
if (isbn.equals(book[i][0])) {
// 因为isbn是唯一的,所以退出循环
index = i;
break;
}
}
return index;
}
// 根据isbn查询图书
static void searchBookByISBN(String isbn) {
System.out.println("ISBN\t书名 \t价格\t出版社 \t作者\t");
for (int i = 0; i < book.length; i++) {
if (isbn.equals(book[i][0])) {
System.out.println(book[i][0] + "\t" + book[i][1] + "\t" + book[i][2] + "\t" + book[i][3] + "\t"
+ book[i][4] + "\t");
// 因为isbn是唯一的,所以退出循环
break;
}
}
}
//返回值版本
// static String[] searchBookByISBN(String isbn) {
// String[] bookInfo = null;
// for (int i = 0; i < book.length; i++) {
// if (isbn.equals(book[i][0])) {
// bookInfo = new String[5];
// bookInfo[0] = book[i][0];
// bookInfo[1] = book[i][1];
// bookInfo[2] = book[i][2];
// bookInfo[3] = book[i][3];
// bookInfo[4] = book[i][4];
// // 因为isbn是唯一的,所以退出循环
// break;
// }
// }
// return book;
// }
// 根据书名模糊查询图书
static void searchByBookName(String bookName){
System.out.println("\tISBN\t书名 \t价格\t出版社 \t作者\t");
for (int i = 0; i < book.length; i++) {
if (book[i][0]!=null && book[i][1].indexOf(bookName)!=-1) {
System.out.println("\t" + book[i][0] + "\t" + book[i][1] + "\t" + book[i][2] + "\t" + book[i][3] + "\t"
+ book[i][4] + "\t");
}
}
}
// 根据出版社查询图书
static void searchBookByPC(String pcName){
System.out.println("\tISBN\t书名 \t价格\t出版社 \t作者\t");
for (int i = 0; i < book.length; i++) {
if (pcName.equals(book[i][3])) {
System.out.println("\t" + book[i][0] + "\t" + book[i][1] + "\t" + book[i][2] + "\t" + book[i][3] + "\t"
+ book[i][4] + "\t");
}
}
}
//返回值版本
// static void searchBookByPC(String pcName){
// String[][] booksInfo = null;
// //得到书籍数组中匹配元素个数
// int count = 0;
// for(int i = 0;i<book.length;i++){
// if(pcName.equals(book[i][3])){
// count++;
// }
// }
// //只有根据出版社名称查询出的数据至少一条,才初始化booksInfo,当返回值为null的时候,表示没有查到一条数据
// if(count>0){
// //根据查询出的数量初始化数组
// booksInfo = new String[count][5];
// //填充数据
// int k = 0;
// for (int i = 0; i < book.length; i++) {
// if (pcName.equals(book[i][3])) {
// for(int j = 0;j<book[i].length;j++){
// booksInfo[k][j] = book[i][j];
// }
// k++;
//
// }
// }
// }
//
// return booksInfo;
// }
// 根据价格范围查询图书
static void searchBookByPrice(int min, int max) {
System.out.println("ISBN\t书名 \t价格\t出版社 \t作者\t");
for (int i = 0; i < book.length; i++) {
if (book[i][0] != null) {
int price = Integer.parseInt(book[i][2]);
if (price >= min && price <= max) {
System.out.println(book[i][0] + "\t" + book[i][1] + "\t" + book[i][2] + "\t" + book[i][3] + "\t"
+ book[i][4] + "\t");
}
}
}
}
// 根据作者查询图书
static void searchBookByAuthor(String author) {
System.out.println("\tISBN\t书名 \t价格\t出版社 \t作者\t");
for (int i = 0; i < book.length; i++) {
if (author.equals(book[i][4])) {
System.out.println("\t" + book[i][0] + "\t" + book[i][1] + "\t" + book[i][2] + "\t" + book[i][3] + "\t"
+ book[i][4] + "\t");
}
}
}
// 默认数据初始化
static void init() {
// 初始化
user[0][0] = "HP001";
user[0][1] = "ken";
user[0][2] = "123";
user[0][3] = "admin";
user[1][0] = "HP002";
user[1][1] = "ryu";
user[1][2] = "123";
user[1][3] = "user";
user[2][0] = "HP003";
user[2][1] = "guile";
user[2][2] = "123";
user[2][3] = "user";
book[0][0] = "001";
book[0][1] = "JAVA高级编程";
book[0][2] = "100";
book[0][3] = "铁道部出版社";
book[0][4] = "张三";
book[1][0] = "002";
book[1][1] = "SQLSERVER高级编程";
book[1][2] = "150";
book[1][3] = "清华出版社";
book[1][4] = "李四";
book[2][0] = "003";
book[2][1] = "JAVA基础入门";
book[2][2] = "50";
book[2][3] = "铁道部出版社";
book[2][4] = "张三";
book[3][0] = "004";
book[3][1] = "ORACLE高级编程";
book[3][2] = "120";
book[3][3] = "清华出版社";
book[3][4] = "王五";
pubCom[0][0] = "清华出版社";
pubCom[0][1] = "武汉市XXXX";
pubCom[0][2] = "aaa";
pubCom[1][0] = "铁道出版社";
pubCom[1][1] = "北京市XXXX";
pubCom[1][2] = "bbb";
pubCom[2][0] = "邮电出版社";
pubCom[2][1] = "南京市XXXX";
pubCom[2][2] = "ccc";
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pdxnb/java_programming_course.git
git@gitee.com:pdxnb/java_programming_course.git
pdxnb
java_programming_course
Java编程课程
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /