package com.day01;
import java.util.ArrayList;
import java.util.Scanner;
public class Booksystem {
static ArrayList<Books> libraries = new ArrayList<Books>();
static ArrayList<Books> Usersbooks = new ArrayList<Books>();
public static void main(String[] args) {
Circulate: while (true) {
System.out.println("——————————欢迎来到懒洋洋的图书管理系统——————————");
System.out.println("请选择:1.登录");
System.out.println("请选择:2.退出");
Scanner scanner = new Scanner(System.in);
String choice = scanner.nextLine();
switch (choice) {
case "1":
Login();
break;
case "2":
break Circulate;
default:
System.out.println("输入错误,请在输入一次");
}
}
}
public static void Login()
{
System.out.println("请选择1.管理员登录");
System.out.println("请选择2.用户登录");
Scanner scanner = new Scanner(System.in);
String choice = scanner.nextLine();
switch (choice) {
case "1"-> BossLogin();
case "2"->UsersLogin();
}
}
public static void BossLogin() {
Boss boss = new Boss();
while (true) {
System.out.println("请输入管理员的用户名");
Scanner scanner = new Scanner(System.in);
String Bossname = scanner.nextLine();
System.out.println("请输入管理员的密码");
String password = scanner.nextLine();
if (Bossname.equals(boss.getName()) && password.equals(boss.getPassword())) {
System.out.println("欢迎您!亲爱的管理员");
BossChoice();
break;
} else {
System.out.println("您的用户名或密码输入错误,请在输入一次");
}
}
}
public static void UsersLogin()
{
Users user = new Users();
while(true) {
System.out.println("请输入用户的用户名");
Scanner scanner = new Scanner(System.in);
String Usersname = scanner.nextLine();
System.out.println("请输入用户的密码");
String password = scanner.nextLine();
if (Usersname.equals(user.getName()) && password.equals(user.getPassword())) {
System.out.println("欢迎您!亲爱的用户");
UserChoice();
break;
} else {
System.out.println("您的用户名或密码输入错误,请在输入一次");
}
}
}
public static void UserChoice()
{
System.out.println("亲爱的用户,请选择你的操作");
System.out.println("1.查看图书馆里所有书");
System.out.println("2.我要借书了!");
System.out.println("3.我要还书了");
System.out.println("4.我要对书进行评价");
System.out.println("5.退出");
Scanner scanner = new Scanner(System.in);
String choice = scanner.nextLine();
switch (choice) {
case "1"->UserBookSawAll(libraries);
case"2"->BorrowBook();
case"3"->Returnbook();
case"4"->Appraisebook();
case"5"->Login();
}
}
public static void UserBookSawAll(ArrayList<Books> libraries)
{
for (int i = 0; i <libraries.size() ; i++) {
System.out.println(libraries.get(i).getId()+" "+libraries.get(i).getName()+" "+libraries.get(i).getAuthor());
}
System.out.println("查看完毕 返回主页面");
UserChoice();
}
public static void BorrowBook()
{
System.out.println("请输入你要所要借书的id");
Scanner scanner = new Scanner(System.in);
int id = scanner.nextInt();
Usersbooks.add(libraries.get(id));
libraries.remove(id-1);
System.out.println("恭喜你,借书完毕,即将返回主页面");
UserChoice();
}
public static void Returnbook()
{
System.out.println("请输入你要所要借书的id");
Scanner scanner = new Scanner(System.in);
int id = scanner.nextInt();
libraries.add(Usersbooks.get(id));
Usersbooks.remove(id);
System.out.println();
System.out.println("恭喜你,还书完毕,即将返回主页面");
UserChoice();
}
public static void Appraisebook()
{
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要评价书的id");
int id = scanner.nextInt();
System.out.println("请输入对书的评论");
String appraise=scanner.nextLine();
System.out.println("我对"+libraries.get(id)+"的评价是"+appraise);
}
public static void BossChoice()
{
System.out.println("亲爱的管理员,请选择你的操作");
System.out.println("1.录入书籍");
System.out.println("2.移除书籍");
System.out.println("3.查看所有书籍");
System.out.println("4.查看所有用户借的书");
System.out.println("5.禁止用户登录");
System.out.println("6.退出登录并返回主界面");
Scanner scanner = new Scanner(System.in);
String choice = scanner.nextLine();
switch (choice) {
case "1"->BookInput();
case"2"-> BookRemove(libraries);
case "3"->BookSeeAll(libraries);
case"4"-> BossSawUser(Usersbooks);
case"5"->Stopusers();
case"6"->Login();
}
}
public static void BookInput()
{
String choose="";
do {
Books book = new Books();
System.out.println("请输入这本书的id");
Scanner scanner = new Scanner(System.in);
String Bookid = scanner.nextLine();
book.setId(Bookid);
System.out.println("请输入这本书的名字");
String Bookname = scanner.nextLine();
book.setName(Bookname);
System.out.println("请输入这本书的作者");
String Bookauthor = scanner.nextLine();
book.setAuthor(Bookauthor);
libraries.add(book);
System.out.println("添加成功");
System.out.println("您是否还想添加书?");
System.out.println("请输入y/n");
choose = scanner.nextLine();
}
while (choose.equals("y"));
BossChoice();
}
public static void BookRemove(ArrayList<Books> libraries) {
int flage=1;
System.out.println("请输入你要删除书的id");
Scanner scanner = new Scanner(System.in);
String Bookid = scanner.nextLine();
for (int i = 0; i < libraries.size(); i++) {
if (libraries.get(i).getId().equals(Bookid)) {
libraries.remove(i);
System.out.println("恭喜你,删除成功");
flage=0;
}
}
if(flage==1)
{
System.out.println("您要删除的书不存在");
}
BossChoice();
}
public static void BookSeeAll(ArrayList<Books> libraries){
for (int i = 0; i <libraries.size() ; i++) {
System.out.println(libraries.get(i).getId()+" "+libraries.get(i).getName()+" "+libraries.get(i).getAuthor());
}
BossChoice();
}
public static void BossSawUser(ArrayList<Books> Usersbooks)
{
for (int i = 0; i < Usersbooks.size() ; i++) {
System.out.println(Usersbooks.get(i).getId()+" "+Usersbooks.get(i).getName()+" "+Usersbooks.get(i).getAuthor());
}
}
public static void Stopusers()
{
System.out.println("您已经开启禁止用户登陆权限");
}
}
标签:case,scanner,管理系统,System,Scanner,println,图书,out
From: https://www.cnblogs.com/lanyangyangxuejava/p/18678818