From 1798c80ade87b9b96674fdbba5fdba150b504649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E4=BA=A8=E4=BC=9F?= <529310475@qq.com> Date: Sun, 25 Dec 2022 23:49:19 +0800 Subject: [PATCH] =?UTF-8?q?25=E5=8F=B7=E7=9A=84=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20221225\344\275\234\344\270\232.md" | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 "11 \351\202\271\344\272\250\344\274\237/20221225\344\275\234\344\270\232.md" diff --git "a/11 \351\202\271\344\272\250\344\274\237/20221225\344\275\234\344\270\232.md" "b/11 \351\202\271\344\272\250\344\274\237/20221225\344\275\234\344\270\232.md" new file mode 100644 index 0000000..0229ce9 --- /dev/null +++ "b/11 \351\202\271\344\272\250\344\274\237/20221225\344\275\234\344\270\232.md" @@ -0,0 +1,153 @@ +# 作业 + +```java +import java.util.Scanner; + +public class GLXT { + + public static void main(String[] args) { + String[] books = new String[10]; + books[0] = "带哦觉得"; + books[1] = "大大"; + books[2] = "大苏打"; + + while (true) { + start(); + int num = choice(); + todo(num, books); + if (num==6){ + break; + } + } + + } + + public static void start() { + System.out.println("---------------------------------\n" + + "- 欢迎使用帝华书籍系统 -\n" + + "- \t\t 1.浏览所有的书籍信息\t\t-\n" + + "\t\t 2.添加书籍信息\t\t-\n" + + "\t\t 3.修改书籍信息\t\t-\n" + + "\t\t 4.删除书籍信息\t\t-\n" + + "\t\t 5.查询书籍信息\t\t-\n" + + "\t\t 6.退出书籍信息\t\t-\n" + + "-----------------------"); + } + + public static int choice() { + System.out.println("选择您的操作:"); + Scanner Sc = new Scanner(System.in); + int num = Sc.nextInt(); + return num; + } + + public static void todo(int num, String[] books) { + switch (num) { + case 1: + //System.out.println("浏览所有的书籍信息"); + viewallbook(books); + break; + case 2: + //System.out.println("添加书籍信息"); + addBook(books); + break; + case 3: + //System.out.println("修改书籍信息"); + ediBook(books); + break; + case 4: + //System.out.println("删除书籍信息"); + DeleteBook(books); + break; + case 5: + SearchBook(books); + //System.out.println("查询书籍信息"); + break; + case 6: + System.out.println("退出书籍信息"); + break; + default: + System.out.println("选择错误,没有该功能"); + } + } + + private static void viewallbook(String[] books) { + for (String name : books) { + if (name==null){ + continue; + } + System.out.print(name + "\t"); + } + } + + public static void addBook(String[] books) { + System.out.println("请输入你要添加的学生姓名"); + Scanner Sc = new Scanner(System.in); + String name = Sc.next(); + int index = searChaArr(books, null); + books[index] = name; + System.out.println("添加成功"); + } + + public static void ediBook(String[] books) { + System.out.println("请输入你要修改的学生姓名"); + Scanner Sc = new Scanner(System.in); + String name = Sc.next(); + int index = searChaArr(books,name); + if (index == -1) { + System.out.println("对不起,您查找的书籍不存在"); + } else { + System.out.println("输入新的书名"); + String NewName = Sc.next(); + books[index] = NewName; + System.out.println("修改成功"); + } + } + + public static int searChaArr(String[] books, String name) { + int index = -1; + if (name == null) { + for (int i = 0; i < books.length; i++) { + if (books[i] == null) { + index = i; + break; + } + } + } else { + for (int i = 0; i < books.length; i++) { + if (name.equals(books[i])) { + index = i; + break; + } + } + + + } + + return index; + } +public static void DeleteBook(String[] books){ + System.out.println("请输入你要删除的学生姓名"); + Scanner Sc = new Scanner(System.in); + String name =Sc.next(); + int index = searChaArr(books,name); + if (index==-1){ + System.out.println("无法删除,因为没有这本书"); + }else{ + books[index]=null; + } + + } + public static void SearchBook(String[] books){ + System.out.println("请输入你要查询的学生姓名"); + Scanner Sc = new Scanner(System.in); + String name =Sc.next(); + int index = searChaArr(books,name); + if (index==-1){ + System.out.println("无效信息,因为没有这本书"); + }else{ + System.out.println("找到了,它在"+(index+1)+"个"); + } + } +} +``` \ No newline at end of file -- Gitee