日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Java创建一个简单的图书管理系统

發布時間:2024/3/13 windows 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java创建一个简单的图书管理系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

由于暫時沒有學過Java,寫的亂七八糟
甚至連內部類和外部類都是寫到一半才知道
不少地方還不清楚是為什么

package 圖書管理系統; import java.util.Scanner; //引入Scanner public class Library {final int book_kinds_number = 5;final int students_number = 5;final int password_length = 4;final int max_borrow_number = 2;public static void main(String[] args) {Book_Manage_System SWJTU_Library = new Library().new Book_Manage_System(); //外部類要優先于內部類出現Scanner input = new Scanner(System.in);int sl_1,sl_2, log = -1;boolean judge = true;boolean judge_1 = true;boolean judge_2 = true;do {judge = true;judge_1 = true;judge_2 = true;do {System.out.println("歡迎使用圖書借閱系統"); //登錄部分System.out.println("登錄...1\n離開...0");sl_1 = input.nextInt();switch(sl_1) {case 1: log = SWJTU_Library.Login();if(log == -1) {System.out.println("密碼輸入錯誤\n");judge_1 = true;}else if(log == -2) {System.out.println("用戶名輸入錯誤\n");}else {judge_1 = false;}break;case 0:System.exit(0);default:System.out.print("輸入有誤,請重新輸入");break;}}while(judge_1);do {System.out.println("功能選擇項"); //功能部分System.out.println("查詢館內圖書...1\n借閱圖書...2\n歸還圖書...3\n退出登錄...0");sl_2 = input.nextInt();switch(sl_2) {case 0:judge_2 = false;judge = true; break;case 1:SWJTU_Library.Show_All_Books();break;case 2:if(log != -1) {SWJTU_Library.Borrow(SWJTU_Library.students[log]);}break;case 3:SWJTU_Library.Show_Student_Books(SWJTU_Library.students[log]);SWJTU_Library.Return(SWJTU_Library.students[log]);break;default:judge_2 = false;break;}}while(judge_2);}while(judge);}public class Book {String name;int num;}public class Student{String name;int borrow_number;String password; //密碼為字符串型Book book[] = new Book[max_borrow_number];public void show_books(){int i;for(i=0;i<max_borrow_number;i++) {if(book[i].num>0) {System.out.print(book[i].name);}if(i!=max_borrow_number - 1) {System.out.print("、");}}}Student(){ //學生的初始化函數int i;for(i=0;i<max_borrow_number;i++) {book[i] = new Book();book[i].num = 0;book[i].name = "";}}}public class Book_Manage_System{Book books[] = new Book[5];Student students[] = new Student[5];public int Login() //登錄函數實現部分{int i, flag = -2;Scanner input = new Scanner(System.in);System.out.print("請輸入用戶名: ");String nm = input.nextLine();System.out.print("請輸入密碼");String key = input.nextLine();for(i=0;i<students_number;i++) {if(students[i].name.equals(nm)) {flag = -1;if(students[i].password.equals(key)) {System.out.println("登錄成功\n歡迎"+students[i].name+"同學");flag = i;break;}}}return flag;}public void Show_All_Books(){int i;for(i=0;i<book_kinds_number;i++) {System.out.print(books[i].name+" "+books[i].num+"本\n");}}public void Borrow(Student stu) //借閱功能實現部分{int i,j;for(i=0;i<book_kinds_number;i++) {System.out.println(books[i].name+" 剩余"+books[i].num);}System.out.println("請問要借哪本書?");Scanner input = new Scanner(System.in);String bk = input.next();for(i=0;i<book_kinds_number;i++) {if(stu.borrow_number == max_borrow_number) {System.out.println("您的借書數量已達上限");break;}if(books[i].name.equals(bk)) { //equals:字符串比較函數,若兩字符串相同則返回trueif(books[i].num==0) {System.out.println("此書已被借完");}else {System.out.println(stu.name+"借出一本《"+books[i].name+"》");for(j=0;j<max_borrow_number;j++) {if(stu.book[j].num == 0) {stu.book[j].name = bk;stu.book[j].num += 1;break;}}books[i].num-=1;stu.borrow_number += 1;}break;}if(i==book_kinds_number-1) {System.out.println("圖書館里沒有《"+bk+"》這本書");}}}public void Show_Student_Books(Student stu){int i;for(i=0;i<max_borrow_number;i++) {if(stu.book[i].num>0) {System.out.println(stu.book[i].name+" "+stu.book[i].num);}}}public void Return(Student stu){int i,j,flag = 0;System.out.println("請問要還哪一本書?");Scanner input = new Scanner(System.in);String rt = input.nextLine();for(i=0;i<max_borrow_number;i++) {if(stu.book[i].name.equals(rt)) { //equals:字符串比較函數,若兩字符串相同則返回truestu.book[i].name="";stu.book[i].num -= 1;for(j=0;j<book_kinds_number;j++) {if(books[j].name.equals(rt)) {System.out.println("歸還成功");books[j].num+=1;break;}}flag = 1;}}if(flag == 0) {System.out.println("您沒有這本書");}}Book_Manage_System() //初始內容:學生的姓名、密碼儲存的地方{books[0] = new Book(); //這里如果不進行動態分配就會報錯books[1] = new Book();books[2] = new Book();books[3] = new Book();books[4] = new Book();students[0] = new Student();students[1] = new Student();students[2] = new Student();students[3] = new Student();students[4] = new Student();books[0].name = "高等數學";books[0].num = 2;books[1].name = "Java編程入門";books[1].num = 2;books[2].name = "漫游者日記";books[2].num = 2;books[3].name = "百武裝戰記";books[3].num = 2;books[4].name = "刀劍神域";books[4].num = 2;students[0].name = "無上輻光";students[0].password = "2337";students[1].name = "失敗冠軍";students[1].password = "2330";students[2].name = "空洞騎士";students[2].password = "1111";students[3].name = "艾米璐";students[3].password = "2222";students[4].name = "桐人";students[4].password = "3333";}} }

總結

以上是生活随笔為你收集整理的Java创建一个简单的图书管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。