package com.company;
public 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);
}
}
package com.company;
/**
* @author dy
* @date 2021/4/15 9:55
*/
public class ArticleSet {
Article[] articles = new Article[50];
}
package com.company;
import java.util.Scanner;
/**
* @author dy
* @date 2021/4/15 9:55
*/
public class ArticleManage {
ArticleSet articleSet = new ArticleSet();
Scanner input = new Scanner(System.in);
public void initial(){
Article xiaoMi9 = new Article();
xiaoMi9.name = "小米9";
xiaoMi9.price = 2799;
xiaoMi9.amount = 60;
xiaoMi9.number = 0;
Article xiaoMiMIX3 = new Article();
xiaoMi9.name = "小米mix3";
xiaoMi9.price = 2049;
xiaoMi9.amount = 40;
xiaoMi9.number = 0;
Article xiaoMiNote7Pro = new Article();
xiaoMi9.name = "小米Note7Pro";
xiaoMi9.price = 699;
xiaoMi9.amount = 80;
xiaoMi9.number = 0;
Article xiaoMiPlay = new Article();
xiaoMi9.name = "小米Play";
xiaoMi9.price = 749;
xiaoMi9.amount = 100;
xiaoMi9.number = 0;
articleSet.articles[0] = xiaoMi9;
articleSet.articles[1] = xiaoMiMIX3;
articleSet.articles[2] = xiaoMiNote7Pro;
articleSet.articles[3] = xiaoMiPlay;
}
public void starMenu(){
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.println("请输入库存:");
int amount = input.nextInt();
Article article = new Article();
article.name=name;
article.price=price;
article.amount=amount;
article.number=0;
for (int i=0;i<articleSet.articles.length;i++){
if (articleSet.articles[i]==null){
articleSet.articles[i]=article;
break;
}
}
}
public void delete(){
System.out.println("请输入商品编号:");
boolean flag = true;
int card = input.nextInt();
for (int i=0;i<articleSet.articles.length;i++){
if (articleSet.articles[i]!=null&&(i+1)==card){
int j=i;
while (articleSet.articles[j+i]!=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 sell(){
System.out.println("请输入你要卖出的商品名称:");
String name = input.next();
boolean flag = true;
for (int i=0;i<articleSet.articles.length;i++){
if (articleSet.articles[i]!=null&&articleSet.articles[i].name.equals(name)){
System.out.println("请输入你要卖出的数量");
int number=input.nextInt();
if (number<=articleSet.articles[i].amount){
articleSet.articles[i].number = articleSet.articles[i].number+number;
articleSet.articles[i].amount = articleSet.articles[i].amount-number;
flag=true;
}
break;
}else {
flag=false;
}
}
if (flag){
System.out.println("卖出商品成功!");
}else {
System.out.println("卖出商品失败");
}
}
public void leaderboard(){
Article[] articles=new 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-i-1;i++){
for (int j=0;j<articles.length-i-1;j++){
if(articles[j+1]!=null){
if (articles[j].number<articles[j+1].number){
Article tempArticle = articles[j];
articles[j]=articles[j+1];
articles[j+1]=tempArticle;
}
}
}
}
System.out.println("**************************");
System.out.println("名次\t销售数量\t商品名称");
for (int i=0;i<articles.length;i++){
if (articles[i]!=null){
System.out.println(i+1+"\t"+articles[i].number+"\t"+articles[i].name);
}
}
}
}
package com.company;
/**
* @author dy
* @date 2021/4/15 10:20
*/
public class Demo {
public static void main(String[] args) {
ArticleManage articleManage = new ArticleManage();
articleManage.initial();
articleManage.starMenu();
}
}
java-超市管理系统
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- org.springframework.beans.factory.UnsatisfiedDependencyEx...
- 1. 介绍 JAVA作为使用的主力语言,掌握下其历史发展也是有必要的。看看从JAVA5开始到现在的JAVA9有哪些...
- 今天青石的票圈出镜率最高的,莫过于张艺谋的新片终于定档了。 一张满溢着水墨风的海报一次次的出现在票圈里,也就是老谋...