只完成了一小部分 刚学习的时候写的东西
管理员账号admin 密码a
注册的时候需要账号要3-5位数字组成
———2017.6.27
ClientMain.java
import static java.lang.System.out;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
public class ClientMain {
static HashSet<Account> set = new HashSet<Account>();
static TreeSet<Book> treeset = new TreeSet<Book>();
// 客户端
public static void main(String[] args) {
// 添加管理员账号
set.add(new Account("admin", "a"));
while (true) {
welcome();
choose();
}
}
// 注册系统
public static void register() {
out.println("进入注册系统.....");
out.println("请输入账号");
boolean flag = true;
String id;
String password = null;
Scanner scanner = new Scanner(System.in);
while (flag) {
while (scanner.hasNext()) {
id = scanner.next();
// 检测账号是否规范
if (id.matches("[1-9]\\d{3,5}")) {
out.println("请输入密码.....");
while (scanner.hasNext()) {
password = scanner.next();
break;
}
// 检测账号是否已经注册
if (set.add(new Account(id, password))) {
flag = false;
out.println("注册成功!!!");
out.println("当前注册的账号有" + set);
break;
} else { // 如果账号已经注册 则返回到输入账号位置
out.println("此帐号已注册.....请重新输入账号...");
}
} else {
out.println("你的账号不规范!!");
}
}
}
}
// 登录系统---->图书管理选择系统
public static void login() {
out.println("进入登录系统..........");
out.println("请输入账号");
String id;
String password = null;
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
id = scanner.next();
// 输入账号过程
if (id.matches("[1-9]\\d{3,5}") | id.equals("admin")) {
out.println("请输入密码.....");
while (scanner.hasNext()) {
password = scanner.next();
break;
}
// 判断账号是否正确
if (set.contains(new Account(id, password))) {
if (id.equals("admin")) {
out.print("管理员登陆成功...");
out.println("进入图书管理系统");
manageChoose();// 进入图书管理系统
} else {
out.print("登陆成功...");
out.println("进入图书管理系统");
manageChoose();// 进入图书管理系统
}
break;
} else { // 返回输入位置
out.println("你的账号或者密码有误");
break;
}
} else { //// 返回输入位置
out.println("您的账号有误.....请重新输入....");
}
}
}
// 登录系统-选择系统
public static void choose() {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String string = scanner.next();
switch (string) {
case ("a"):
case ("A"): {
login();
break;
}
case ("b"):
case ("B"): {
register();
break;
}
case ("c"):
case ("C"): {
System.exit(0);
break;
}
}
break;
}
}
// 登录欢迎界面
public static void welcome() {
out.println("************************************************************");
out.println("* *");
out.println("* *");
out.println("* *");
out.println("* *");
out.println("* 欢迎进入图书管理系统 V1.0 *");
out.println("* *");
out.println("* *");
out.println("* *");
out.println("* Copyright ? 2017 by lijing *");
out.println("************************************************************");
out.println(" 请选择功能: 用户登录(A) 用户注册(B) 退出系统(C)");
}
// 图书馆界面
public static void welcome2() {
System.out.println("请选择功能: 查看图书(A) 添加图书(B) 修改图书(C) 删除图书(D)");
System.out.println("修改用户名(E) 修改密码(F) 修改用户(G) 删除用户(H) 查看所有用户(I) 注销(Q)");
}
// 图书管理系统-选择系统
public static void manageChoose() {
String choose = null;
Scanner scanner = new Scanner(System.in);
// 检测输入的按键是什么 进入相应的功能中
while(true){
welcome2();
while (scanner.hasNext()) {
choose = scanner.next();
break;
}
switch (choose) {
case ("a"):
case ("A"): {
out.println("查看图书");
check();
break;
}
case ("b"):
case ("B"): {
out.println("添加图书");
add();
break;
}
case ("c"):
case ("C"): {
out.println("修改图书");
break;
}
case ("q"):
case ("Q"): {
out.println("注销用户");
return;
}
}
}
}
// 图书查看系统
public static void check() {
// String sort = "A";
/*switch(sort){
case("a"):
case("A"):{
IdSort compartor = new IdSort();
}
}*/
System.out.println("|书名| |作者| |出版社| |价格| |书号| |出版日期|");
Iterator<Book> it = treeset.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
System.out.println("请选择查看方式 : (A)价格排序 (B)作者排序 (C)出版日期排序 (E)返回上一级");
}
// 图书添加系统
public static void add() {
Scanner scanner = new Scanner(System.in);
String name = null;
String author = null;
String publishing = null;
double price = 0;
int id = 0;
String date = null;
System.out.println("请输入书名");
while (scanner.hasNext()) {
name = scanner.next();
break;
}
System.out.println("请输入作者");
while (scanner.hasNext()) {
author = scanner.next();
break;
}
System.out.println("请输入出版社");
while (scanner.hasNext()) {
publishing = scanner.next();
break;
}
System.out.println("请输入价格");
while (scanner.hasNextDouble()) {
price = scanner.nextDouble();
break;
}
System.out.println("请输入书号");
while (scanner.hasNextInt()) {
id = scanner.nextInt();
break;
}
System.out.println("请输入出版日期");
while (scanner.hasNext()) {
date = scanner.next();
break;
}
treeset.add(new Book(name, author, publishing, price, id, date));
}
}
Book.java
public class Book implements Comparable<Book> {
String name;
String author;
String publishing;
double price;
int id;
String date;
public Book(String name, String author, String publishing, double price, int id, String date) {
this.name = name;
this.author = author;
this.publishing = publishing;
this.price = price;
this.id = id;
this.date = date;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.name+" "+this.author+" "+this.publishing+" "+this.price+" "+this.id+" "+this.date;
}
@Override
public int compareTo(Book o) {
// TODO Auto-generated method stub
return this.id-o.id;
}
}
Account.java
/**
* Created by LiJing on 2017/6/27.
*/
public class Account {
String id;
String password;
public Account(String id, String password) {
this.id = id;
this.password = password;
}
@Override
public String toString(){
return this.id;
}
@Override
public int hashCode(){
//让管理员可以登录 同时防止普通用户注册管理员
if(this.id.equals("admin")){
return 0;
}
return Integer.parseInt(this.id);
}
@Override
public boolean equals(Object o){
Account account=(Account)o;
return this.id.equals(account.id)&&this.password.equals(account.password)/**/;
}
}