商店管理系统
/**
* @outhor chenlong
* @date 2021/4/14 {TIME}
**/
public class sdgl {
/**
* 商品的类
*/
public static class Article {
public String name; //商品名称
public int amount; //商品库存数量
public double price; //商品价格
public int number; //商品出售数量
/*
书籍信息展示
*/
public void print(int index){
System.out.println(index + "\t" + name + "\t" + price +"\t" + amount + "\t" + number);
}
}
}
/**
* @outhor chenlong
* @date 2021/4/14 {TIME}
**/
public class ArticleSet {
public static sdgl.Article[] articles;
/*
商品合集(仓库)
*/
sdgl.Article[] articlse = new sdgl.Article[24];
}
import java.util.Scanner;
/**
* @outhor chenlong
* @date 2021/4/14 {TIME}
**/
public class ArticleManage {
/*
管理类
*/
// 创建一个实体的仓库对象,并初始化
ArticleSet articleSet = new ArticleSet();
Scanner input = new Scanner(System.in);
/*
初始化商品
*/
public void initial() {
sdgl.Article xiaomi6 = new sdgl.Article();
xiaomi6.name = "小米6";
xiaomi6.price = 648;
xiaomi6.amount = 1000;
xiaomi6.number = 0;
sdgl.Article mik30pro = new sdgl.Article();
mik30pro.name = "红米k30pro";
mik30pro.price = 1999;
mik30pro.amount = 2000;
mik30pro.number = 0;
sdgl.Article xiaomi11 = new sdgl.Article();
xiaomi11.name = "小米11";
xiaomi11.price = 3999;
xiaomi11.amount = 1000;
xiaomi11.number = 0;
sdgl.Article heisha4 = new sdgl.Article();
heisha4.name = "黑鲨4";
heisha4.price = 3999;
heisha4.amount = 1000;
heisha4.number = 0;
articleSet.articlse[0] = xiaomi6;
articleSet.articlse[1] = mik30pro;
articleSet.articlse[2] = xiaomi11;
articleSet.articlse[3] = heisha4;
}
/*
菜单切换
*/
public void startMenu() {
boolean flag = true;//是否继续操作
do {
System.out.println("欢迎使用商店管理系统");
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("请选择要执行的操作:");
int choice = input.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("卖出商品");
break;
case 6:
System.out.println("谢 谢 使 用!");
flag = false;
break;
default:
System.out.println("输入不符合要求请重新选择!");
break;
}
} while (flag);
} public void search(){
System.out.println("编号\t名称\t价格\t库存\t售出");
for (int i = 0; i < ArticleSet.articles.length; i++) {
if (ArticleSet.articles[i] != null) {
ArticleSet.articles[i].print(i + 1);
}
}
/**
* 查看商品信息
*/
}public void add(){
System.out.println("请输入商品名称");
String name = input.next();
System.out.println("请输入价格");
int price = input.nextInt();
System.out.print("请输入库存:");
int amount = input.nextInt();
sdgl.Article article = new sdgl.Article();
article.name = name;
article.price = price;
article.amount = amount;
article.number = 0;
for (int i = 0 ; i < articleSet.articlse.length; i++){
if (articleSet.articlse[i] == null){
articleSet.articlse[i] =article;
break;
}
}
/**
*卖出商品
*/
}public void delete() {
System.out.println("请输入商品名称:");
boolean flag = true ; //是否卖出成功
int card = input.nextInt();
for (int i = 0; i < articleSet.articlse.length;i++){
if (articleSet.articlse[i]!= null&&(i+1)==card){
int j=i;
while (articleSet.articlse[j+i]!=null){
articleSet.articlse[j]=articleSet.articlse[j+i];
j++;
}
articleSet.articlse[j] = null;
flag = true;
break;
}else {
flag = false;
}
}
if (flag){
System.out.println("卖出成功");
}else {
System.out.println("卖出失败,号码错误,请重新操作!");
}
}public void leaderboard() {
sdgl.Article[] articles = new sdgl.Article[50];
for (int i = 0; i < articles.length; i++) {
if (ArticleSet.articles[i] != null) {
articles[i] = ArticleSet.articles[i];
}
}
for (int i = 0; i < articles.length - 1; i++) {
for (int j = 0; j < articles.length - i - 1; j++) {
if (articles[j].number < articles[j + 1].number) {
sdgl.Article temoArticle = articles[j];
articles[j] = articles[j + 1];
articles[j + 1] = temoArticle;
}
}
}
System.out.println("*******************************");
System.out.println("名次\t销售量\t商品名称");
for (int i = 0 ; i < articles.length;i++){
if (articles[i]!= null){
System.out.println( + 1 + " \t" +articles[i].number + "\t"+ articles[i].name);
}
}
}
}