一个简单的商品销售系统

该程序创建了一个简单的商品销售系统,使用Java编程语言。用户可以输入6种商品的序号、名称、价格和数量。系统能计算所有商品的价格平均值、总数量和总价值,并对商品按价格进行排序。程序包含无限循环,允许用户选择不同的查询操作,如输入商品信息、查看统计信息或退出系统。
摘要由CSDN通过智能技术生成

制作一个简单的商品销售系统

import java.util.Scanner;

class Pro {
    static String[] name = new String[6];//名称
    static int[] number = new int[6];//序号
    static int[] price = new int[6];//价格
    static int[] sum = new int[6];//数量

    public static void ProductInformation() {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6; i++) {
            number[i] = sc.nextInt();
            name[i] = sc.next();
            price[i] = sc.nextInt();
            sum[i] = sc.nextInt();
        }

    }

    public static void compute() {
        int averge=0;
        int number2=0;
        int totalValue=0;
        for(int i=0;i<6;i++){
              averge+=price[i];
              number2+=sum[i];
              totalValue+=price[i]*sum[i];
        }
    }

    public static void sort() {
        int price1[] = new int[6];
        for (int i = 0; i < 6; i++) {
            price1[i] = price[i];
        }
        for (int j = 0; j < 6 - 1; j++) {
            for (int i = 0; i < 6 - j - 1; i++) {
                if (price1[i] > price1[i + 1]) {
                    int x = price1[i + 1];
                    price1[i + 1] = price1[i];
                    price1[i] = x;
                }
            }
        }
        for (int i = 0; i < 6; i++) {
              for(int j=0;j<6;j++){
                  if (price[j]==price1[i])
                  {
                      System.out.println(number[j]);
                      break;
                  }
              }
        }
    }
}
public class Product {
    public static void main(String[] args) {
        while (true){//无限循环
        System.out.println("欢迎进入商品销售系统!");
        System.out.println("0:首先输入6种商品信息");//序号 名称 价格 数量。
        System.out.println("本次查询的功能有以下   ");
        System.out.println("1:计算所有商品价格平均值,商品总数量,总价值");
        System.out.println("2:为商品进行价格排序");
        System.out.println("3:退出系统");
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        switch (x) {
            case 0:
                Pro.ProductInformation();
                break;
            case 1:
                Pro.compute();
                break;
            case 2:
                Pro.sort();
                break;
            case 3:
                System.out.println("本次查询结束,欢迎下次查询");
                break;
        }
        }
    }
}
好的,这是一个简单商品销售系统的C语言代码示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_PRODUCTS 100 struct product { char name[20]; int stock; float price; }; struct product products[MAX_PRODUCTS]; int num_products = 0; void add_product() { if (num_products == MAX_PRODUCTS) { printf("无法添加更多商品!\n"); return; } struct product p; printf("请输入商品名称:"); scanf("%s", p.name); printf("请输入商品库存:"); scanf("%d", &p.stock); printf("请输入商品价格:"); scanf("%f", &p.price); products[num_products++] = p; printf("商品添加成功!\n"); } void list_products() { printf("%-20s%-10s%-10s\n", "名称", "库存", "价格"); for (int i = 0; i < num_products; i++) { printf("%-20s%-10d%-10.2f\n", products[i].name, products[i].stock, products[i].price); } } void sell_product() { char name[20]; printf("请输入要出售的商品名称:"); scanf("%s", name); for (int i = 0; i < num_products; i++) { if (strcmp(products[i].name, name) == 0) { if (products[i].stock == 0) { printf("商品库存不足,无法出售!\n"); return; } products[i].stock--; printf("商品出售成功!\n"); return; } } printf("未找到此商品!\n"); } int main() { int choice; do { printf("请选择操作:\n"); printf("1. 添加商品\n"); printf("2. 查看商品\n"); printf("3. 出售商品\n"); printf("4. 退出\n"); printf("请输入选项编号:"); scanf("%d", &choice); switch (choice) { case 1: add_product(); break; case 2: list_products(); break; case 3: sell_product(); break; case 4: printf("已退出!\n"); break; default: printf("无效的选项!\n"); break; } } while (choice != 4); return 0; } ``` 这个销售系统支持添加商品、查看商品和出售商品等功能。你可以根据需要进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值