- import java.util.Scanner;
- class Demo
- {
- private static Book[] bookArray = new Book[10];//最大容量,最多管理10本图书
- private static int bookIndex=0;//存储当前bookArray中可用的索引位置;
- private static Scanner sc = new Scanner(System.in);//接收用户输入。被所有的方法共享
-
- //此方法初始化bookArray数组
- public static void init(){
- /*
- Book b1 = new Book("javaSE基础编程","刘编程",88,"清华出版社");
- bookArray[bookIndex]=b1;
- bookIndex++;
- */
- bookArray[bookIndex++] = new Book("javaSE基础编程","刘编程",88,"清华出版社");
- bookArray[bookIndex++] = new Book("javaME手机游戏","张先森",99,"上海出版社");
- bookArray[bookIndex++] = new Book("javaEE高级WEB","李四",75,"北京出版社");
- }
- //显示欢迎界面
- public static void printWelcome(){
- System.out.println(" $$$$$$¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥$$$$$$");
- System.out.println(" ¥¥ $$ $$ ¥¥");
- System.out.println(" ¥¥ $$ $$ ¥¥");
- System.out.println(" $$ 欢迎使用图书管理系统 $$");
- System.out.println(" $$ V1.0版 $$");
- System.out.println(" $$ $$");
- System.out.println(" $$ 作者: 日期:2015-09-04 $$");
- System.out.println(" $$ $$");
- System.out.println(" ¥¥ $$ $$ ¥¥");
- System.out.println(" ¥¥ $$ $$ ¥¥");
- System.out.println(" $$$$$$¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥$$$$$$");
- }
- //添加图书
- public static void addBook(){
- //先判断数组是否已满
- if(bookIndex == bookArray.length){
- System.out.println("对不起,数据已满!");
- return;
- }
- System.out.println("请输入图书信息:");
- System.out.println("书名:");
- String name = sc.next();
- System.out.println("作者:");
- String author = sc.next();
- System.out.println("价格:");
- double price = sc.nextDouble();
- System.out.println("出版社:");
- String publish = sc.next();
- //实例化一个Book对象
- Book book = new Book(name,author,price,publish);
- //将对象存储到数组
- bookArray[bookIndex++] = book;
- System.out.println("数据已存储!");
- return;
- }
- //查看所有图书
- public static void showAllBook(){
- System.out.println("=================================================");
- System.out.println("\t序列\t书名\t\t作者\t价格\t出版社");
- System.out.println("=================================================");
- for (int i=0; i<bookArray.length; i++)
- {
- if (bookArray[i]==null)
- {
- System.out.println("=================================================");
- return;
- }
- Book book = bookArray[i];
- System.out.println("\t"+(i+1)+"\t"+book.getName()+"\t"+book.getAuthor()+"\t"+book.getPrice()+"\t"+book.getPublish());
- }
- System.out.println("=================================================");
- }
- public static void main(String[] args){
- //初始化数据
- init();
- //显示欢迎界面
- printWelcome();
- //显示菜单
- loop:
- while(true){
- System.out.println("@@@@@@@@@@@@@@@---------¥¥¥¥¥¥¥¥¥¥¥¥¥¥-----------@@@@@@@@@@@@@@@");
- System.out.println(" 1.添加图书 2.删除图书 3.修改图书 4.查询图书 5.查看全部图书 6.退出系统 ");
- System.out.println("@@@@@@@@@@@@@@@---------¥¥¥¥¥¥¥¥¥¥¥¥¥¥-----------@@@@@@@@@@@@@@@");
- System.out.println("请选择你的操作:");
- int op = sc.nextInt();
- switch(op){
- case 1://添加图书
- addBook();
- break;
- case 2://删除图书
- case 3://修改图书
- case 4://查询图书
- case 5://查看全部图书
- showAllBook();
- break;
- case 6://退出系统
- System.out.println("谢谢使用,再见!!");
- break loop;
- }
- }
- }
- }
复制代码 |
|