首先图书馆系统你需要想到的是普通用户和管理用户所拥有的功能,从而进行下一步。
普通用户的功能:
("1.查找图书");
("2.借阅图书");
("3.归还图书");
("0.退出系统");
管理员用户的功能:
("1.查找图书");
("2.新增图书");
("3.删除图书");
("0.退出系统");
想到一个大类作为父类比如user
public class user { protected String name; public user(String name){ this.name=name; } public void setName(String name) { this.name = name; } public String getName() { return name; }
然后使用者包括普通用户和管理者 Ordinary Admirer
针对Ordinary类进行继承父类user(切记得重载父类上带有参数的方法)
public Ordinary(String name) { super(name);
针对 Admirer类进行继承父类user(切记得重载父类上带有参数的方法)
public Admirer(String name){ super(name);
接着针对图书方面进行一系列的操作,比如书,还有书架(book,bookLisa),以书建一个包,方便后续操作。
BOOk:
package book; public class book { public String name; public String author; public int price; public boolean borrow; public book(String name, String author, int price) { this.name = name; this.author=author; this.price=price; } public void setName(String name) { this.name = name; } public String getName() { return name; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; }
bookLisa:
package book; public class bookLisa { public book[] bookLisa = new book[10]; public static int getUsedLisa() { return usedLisa; } public static int usedLisa;//表达暑假上有几本书 public bookLisa(){ bookLisa[0]= new book("三国演义","罗贯中",50); bookLisa[1]= new book("哈哈","帅哥",55); bookLisa[3]= new book("杀杀杀","啧啧啧",88); }
public void usedLisa(){ this.usedLisa=3; }
书和用户都解决了,所以我们要解决操作问题 IOoperate;其次要根据前面用户和管理所进行的操作进行一系列的操作比如新增,查找等等之类;
IOoperate:
package Ioperate; import book.bookLisa; public interface IOoperate { default void work(bookLisa B){ } }
public class Addoperate implements IOoperate{ void work(){ System.out.println("新增图书"); } }
Addoperate:
package operate; public class Addoperate implements IOoperate{ void work(){ System.out.println("新增图书"); } }
borrowoperate:
package operate; public class borrowoperate implements IOoperate{ void work(){ System.out.println("借阅图书"); } }
Deleoperate:
package operate; public class Deleoperate implements IOoperate{ void work(){ System.out.println("删除图书"); } }
exitoperate:
package operate; public class exitoperate implements IOoperate{ void work(){ System.out.println("退出系统"); System.exit(0); } }
returnoperate:
package operate; public class returnoperate implements IOoperate{ void work(){ System.out.println("归还图书"); } }
seekoperate:
public class seekoperate implements IOoperate{ void work(){ System.out.println("查找图书");
}
写完以上操作过后,就要想想主方法如何去调用。
public class main { public static user login(){ Scanner scanner=new Scanner(System.in); System.out.println("请输入你的名字"); String name= scanner.nextLine(); System.out.println("请输入你的身份,1-管理员,0-普通成员"); int choice= scanner.nextInt(); if(choice==1){ return new Admirer(name); } if(choice==0){ return new Ordinary(name); } return null; } public static void main(String[] args) { user u = login();//哪个用户就用哪个菜单 bookLisa b = new bookLisa(); u.menus(); while (true) { int choice = u.menus();
}
以上就是图书馆系统,希望对你们有帮助。