package edu.xcdq.mall;
import java.util.Arrays;
import java.util.Scanner;
/**
?*商品管理類
?*/
public class ArticleManage {
??? ArticleSet articleSet = newArticleSet();
??? public void initial () {
??????? Article xiyouji = newArticle();
? ??????xiyouji.setArticle("西游記" , 10, 1,0);
??????? Article hongloumen = newArticle();
??????? hongloumen.setArticle("紅樓夢",20 ,1, 0);
??????? Article tutu = new Article();
??????? tutu.setArticle("圖圖",10,1,0 );
??????? articleSet.articles[0] =xiyouji;
??????? articleSet.articles[1] =hongloumen;
??????? articleSet.articles[2] =tutu;
??? }
??? public void startMenu () {
??????? boolean flag = true ;
??????? do {
???????????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退出");
? ??????????System.out.println("********************************");
??????????? System.out.println("請輸入你要執(zhí)行的功能編號:");
??????????? Scanner scanner = newScanner(System.in);
??????????? int gongnengBianhao =scanner.nextInt();
??????????? switch ( gongnengBianhao) {
??????????????? case 1:
???????????????????System.out.println("新增圖書");
??????????????????? add();
??????????????????? break;
??????????????? case 2:
???????????????????System.out.println("查看圖書");
??????????????????? chakan();
?????? ?????????????break;
??????????????? case 3:
???????????????????System.out.println("刪除圖書");
??????????????????? delete();
??????????????????? break;
??????????????? case 4:
???????????????????System.out.println("借出圖書");
??????????????????? sell();
??????????????????? break;
??????????????? case 5:
???????????????????System.out.println("歸還圖書");
??????????????????? leaderboard();
??????????????????? break;
??????????????? case 6:
???????????????????System.out.println("感謝使用辐烂,已經(jīng)退出");
????????? ??????????flag = false ;
??????????????????? break;
??????????????? default:
???????????????????System.out.println("你輸入的功能編號有誤");
??????????????????? break;
??????????? }
??????? }while ( flag );
??? }
??? public void leaderboard(){
??????? int count = 0 ;
??????? for ( int i = 0 ; i
??????????? if (articleSet.articles[i] != null ) {
??????????????? count ++ ;
??????????? }
??????? }
??????? Article[] newTemp = newArticle[count];
??????? for ( int i =0 ; i < count; i ++ ) {
??????????? newTemp[i] =articleSet.articles[i];
??????? }
??????? for ( int i =0 ; i
??????????? for ( int j = 0 ; j
??????????????? if ( newTemp[j+1] != null) {
??????????????????? if (newTemp[j].number < newTemp[j+1].number ) {
??????????????????????? Article temp= newTemp[j];
??????????????????????? newTemp[j] =newTemp[j+1];
??????????????????????? newTemp[j+1]= temp;
??????????????????? }
??????????????? }
??????????? }
??????? }
??????? //顯示名次
??????? System.out.println("名次: \t 銷售數(shù)量 \t 商品名稱");
??????? for (int i = 0; i
??????????? System.out.println( (i+1)+"\t" + newTemp[i].number + "\t" + newTemp[i].name );
??????? }
??? }
??? public void sell(){
??????? System.out.println("請輸入你要借出的書的名字:");
??????? Scanner scanner = newScanner(System.in);
??????? String name = scanner.next();
??????? boolean flag = true;
??????? for (int i= 0 ; i
??????????? if (articleSet.articles[i] != null &&articleSet.articles[i].name.equals(name) ) {
???????????????System.out.println("請輸入要借出的數(shù)量:");
??????????????? int maichu =scanner.nextInt();
??????????????? if ( maichu < articleSet.articles[i].amount) {
???????????????????articleSet.articles[i].amount = articleSet.articles[i].amount - maichu;
???????????????????articleSet.articles[i].number = articleSet.articles[i].number + maichu;
??????????????????? flag = true;
??????????????? }else {
??????????????????? flag = false;
???????????????????System.out.println("庫存不夠了");
??????????????? }
??????????????? break;
??????????? } else {
??????????????? flag = false;
??????????? }
??????? }
??????? if(flag) {
??????????? System.out.println("賣出成功");
??????? }else{
??????????? System.out.println("賣出失敗");
??????? }
??? }
??? private void delete() {
??????? System.out.println("輸入你要刪除的書編號:");
??????? Scanner scanner = newScanner(System.in);
?? ?????int delNo = scanner.nextInt();
??????? boolean flag = true;
??????? for ( int i = 0 ; i
??????????? if ( delNo ==? (i+1) && articleSet.articles[i] !=null ) {
??????????????? int j = i ; //備份下標(biāo)
?????????? ?????while ( articleSet.articles[j+1] != null ){
???????????????????articleSet.articles[j] = articleSet.articles[j+1] ;
??????????????????? j++ ;
??????????????? }
???????????????articleSet.articles[j] = null;
??????????????? flag = true;
??????? ????????break;
??????????? } else {
??????????????? flag =false;
??????????? }
??????? }
??????? if (flag) {
??????????? System.out.println("刪除成功");
??????? }else {
??????????? System.out.println("刪除失敻松贰挨下!");
??????? }
??? }
??? public void chakan() {
??????? System.out.println("編號 \t 名稱 \t 庫存 \t 單價 \t 售出數(shù)量");
??????? for (int i = 0; i
??????????? if (articleSet.articles[i] != null ) {
???????????????articleSet.articles[i].print(i+1);
??????????? }
??????? }
??? }
??? public void add() {
??????? Scanner scanner = newScanner(System.in);
??????? System.out.println("請輸入書的名字:");
??????? String name = scanner.next();
??????? System.out.println("價格:");
??????? double price =scanner.nextDouble();
??????? System.out.println("庫存:");
??????? int kucun =scanner.nextInt();
??????? System.out.println("售出數(shù)量:");
??????? int number? = scanner.nextInt();
??????? Article newArticle = newArticle();
??????? newArticle.setArticle(name ,kucun ,price , number );
??????? for ( int i =0 ; i
??????????? if (articleSet.articles[i] == null ) {
???????????????articleSet.articles[i]? =newArticle;
??????????????? break;
??????????? }
??????? }
??? }
}