```
給予圖書屬性
```
package com;
public class leiXing {
? ? public String name;
? ? public int num;
? ? public String date ;
? ? public void print(int index){
? ? ? ? System.out.println( index +"\t"+num+"\t"+name+"\t"+date);
? ? }
}
```
給予圖書儲存空間
```
package com;
public class chuShiHua {
? ? leiXing[] leiXings = new leiXing[50] ;
}
···
實現(xiàn)圖書管理系統(tǒng)功能
```
package com;
import java.util.Scanner;
public class shangPingChu {
? ? chuShiHua chuShiHuas =new chuShiHua() ;
? Scanner scanner = new Scanner(System.in) ;
? public void initial(){
? ? ? leiXing shu1=new leiXing();
? ? ? shu1.num =1;
? ? ? shu1.name ="哈哈哈" ;
? ? ? shu1.date ="07-18" ;
? ? ? leiXing shu2 =new leiXing() ;
? ? ? shu2.num =2;
? ? ? shu2.name ="呼呼" ;
? ? ? shu2 .date ="09-12" ;
? ? ? leiXing shu3 =new leiXing() ;
? ? ? shu3.num = 3;
? ? ? shu3.name ="嘿嘿" ;
? ? ? shu3.date ="06-25" ;
? }
public? void starMenu(){
? ? ? boolean flag? ;
? ? ? do {
? ? ? ? ? System.out.println("歡迎使用圖書管理系統(tǒng)");
? ? ? ? ? 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("-----------------------");
? ? ? ? ? System.out.println("請選擇要執(zhí)行的操作");
? ? ? ? ? int choice =scanner.nextInt();
? ? ? ? ? switch (choice){
? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? System.out.println("查看圖書信息");
? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? System.out.println("新增圖書信息");
? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? System.out.println("刪除圖書信息");
? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? case 4:
? ? ? ? ? ? ? ? ? System.out.println("圖書銷售排行榜");
? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? case 5:
? ? ? ? ? ? ? ? ? System.out.println("推出");
? ? ? ? ? ? ? ? ? flag = false;
? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? System.out.println("輸入不符合要求");
? ? ? ? ? }
? ? ? ? flag = true ;
? ? ? }while (flag) ;
}
public void? search(){
? ? System.out.println("編號\t書名\t借出日期");
? ? for (int i = 0; i <chuShiHuas.leiXings.length ; i++) {
? ? ? ? if (chuShiHuas.leiXings[i]!= null){
? ? ? ? ? ? chuShiHuas.leiXings[i].print(i+1);
? ? ? ? }
? ? }
}public void add(){
? ? ? Scanner scanner = new Scanner(System.in);
? ? ? ? System.out.println("請輸入書名");
? ? ? ? String name =scanner.next();
? ? ? ? System.out.println("請輸入編號");
? ? ? ? String num = scanner.next();
? ? ? ? leiXing haha =new leiXing();
? ? ? ? haha.name =name;
? ? ? ? haha.num =0 ;
? ? ? ? for (int i = 0; i <chuShiHuas.leiXings.length ; i++) {
? ? ? ? ? ? if (chuShiHuas.leiXings[i] ==null){
? ? ? ? ? ? ? ? chuShiHuas.leiXings[i] =haha ;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
```