Java代码 超市信息管理系统 要求: 1. 超市商品信息的增删改查(例如商品编号、商品名称、单价、、购买数量等) 2. 超市销售排
时间: 2023-07-10 14:30:47 浏览: 94
名与统计分析功能 3. 超市库存管理(例如进货、出货、库存报警等) 4. 超市员工管理(例如员工信息的增删改查、员工工资的计算等)
这是一个比较复杂的系统,需要用到Java的面向对象编程思想。你需要设计好各个类的属性和方法,并且实现它们之间的交互。以下是一个简单的伪代码示例:
// 商品类
class Product {
int id;
String name;
double price;
int quantity;
// 构造函数
public Product(int id, String name, double price, int quantity) {
this.id = id;
this.name = name;
this.price = price;
this.quantity = quantity;
}
// getter 和 setter 方法
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public double getPrice() { return price; }
public void setPrice(double price) { this.price = price; }
public int getQuantity() { return quantity; }
public void setQuantity(int quantity) { this.quantity = quantity; }
// toString 方法
public String toString() {
return "ID: " + id + ", Name: " + name + ", Price: " + price + ", Quantity: " + quantity;
}
}
// 商品管理类
class ProductManager {
List<Product> products = new ArrayList<>();
// 添加商品
public void addProduct(Product product) {
products.add(product);
}
// 删除商品
public void deleteProduct(int id) {
for (Product product : products) {
if (product.getId() == id) {
products.remove(product);
break;
}
}
}
// 修改商品
public void updateProduct(int id, String name, double price, int quantity) {
for (Product product : products) {
if (product.getId() == id) {
product.setName(name);
product.setPrice(price);
product.setQuantity(quantity);
break;
}
}
}
// 查找商品
public Product findProduct(int id) {
for (Product product : products) {
if (product.getId() == id) {
return product;
}
}
return null;
}
// 显示所有商品
public void showAllProducts() {
for (Product product : products) {
System.out.println(product);
}
}
}
// 销售管理类
class SalesManager {
List<Product> soldProducts = new ArrayList<>();
// 添加销售记录
public void addSale(Product product) {
soldProducts.add(product);
}
// 统计销售额
public double getTotalSales() {
double total = 0;
for (Product product : soldProducts) {
total += product.getPrice() * product.getQuantity();
}
return total;
}
// 统计销售量
public int getTotalQuantity() {
int total = 0;
for (Product product : soldProducts) {
total += product.getQuantity();
}
return total;
}
// 显示销售排名
public void showSalesRank() {
// TODO: 实现销售排名功能
}
}
// 库存管理类
class InventoryManager {
List<Product> inventory = new ArrayList<>();
// 添加库存
public void addInventory(Product product) {
inventory.add(product);
}
// 出库
public void sellProduct(int id, int quantity) {
for (Product product : inventory) {
if (product.getId() == id) {
if (product.getQuantity() < quantity) {
System.out.println("库存不足!");
return;
}
product.setQuantity(product.getQuantity() - quantity);
break;
}
}
}
// 入库
public void addProduct(int id, int quantity) {
for (Product product : inventory) {
if (product.getId() == id) {
product.setQuantity(product.getQuantity() + quantity);
break;
}
}
}
// 库存报警
public void checkInventory() {
for (Product product : inventory) {
if (product.getQuantity() <= 10) {
System.out.println("商品 " + product.getName() + " 库存不足,当前库存为 " + product.getQuantity());
}
}
}
}
// 员工类
class Employee {
int id;
String name;
double salary;
// 构造函数
public Employee(int id, String name, double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}
// getter 和 setter 方法
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public double getSalary() { return salary; }
public void setSalary(double salary) { this.salary = salary; }
// toString 方法
public String toString() {
return "ID: " + id + ", Name: " + name + ", Salary: " + salary;
}
}
// 员工管理类
class EmployeeManager {
List<Employee> employees = new ArrayList<>();
// 添加员工
public void addEmployee(Employee employee) {
employees.add(employee);
}
// 删除员工
public void deleteEmployee(int id) {
for (Employee employee : employees) {
if (employee.getId() == id) {
employees.remove(employee);
break;
}
}
}
// 修改员工信息
public void updateEmployee(int id, String name, double salary) {
for (Employee employee : employees) {
if (employee.getId() == id) {
employee.setName(name);
employee.setSalary(salary);
break;
}
}
}
// 查找员工
public Employee findEmployee(int id) {
for (Employee employee : employees) {
if (employee.getId() == id) {
return employee;
}
}
return null;
}
// 显示所有员工
public void showAllEmployees() {
for (Employee employee : employees) {
System.out.println(employee);
}
}
}
// 主函数
public static void main(String[] args) {
// 创建商品管理类实例
ProductManager productManager = new ProductManager();
// 添加商品
Product product1 = new Product(1, "可乐", 2.5, 100);
Product product2 = new Product(2, "薯片", 5, 50);
productManager.addProduct(product1);
productManager.addProduct(product2);
// 显示所有商品
productManager.showAllProducts();
// 修改商品信息
productManager.updateProduct(1, "雪碧", 3, 200);
// 删除商品
productManager.deleteProduct(2);
// 查找商品
Product product = productManager.findProduct(1);
System.out.println(product);
// 创建销售管理类实例
SalesManager salesManager = new SalesManager();
// 添加销售记录
salesManager.addSale(product1);
salesManager.addSale(product2);
// 统计销售额和销售量
System.out.println("总销售额:" + salesManager.getTotalSales());
System.out.println("总销售量:" + salesManager.getTotalQuantity());
// 显示销售排名
salesManager.showSalesRank();
// 创建库存管理类实例
InventoryManager inventoryManager = new InventoryManager();
// 添加库存
inventoryManager.addInventory(product1);
inventoryManager.addInventory(product2);
// 出库
inventoryManager.sellProduct(1, 50);
// 入库
inventoryManager.addProduct(2, 100);
// 库存报警
inventoryManager.checkInventory();
// 创建员工管理类实例
EmployeeManager employeeManager = new EmployeeManager();
// 添加员工
Employee employee1 = new Employee(1, "张三", 3000);
Employee employee2 = new Employee(2, "李四", 3500);
employeeManager.addEmployee(employee1);
employeeManager.addEmployee(employee2);
// 显示所有员工
employeeManager.showAllEmployees();
// 修改员工信息
employeeManager.updateEmployee(1, "小张", 3500);
// 删除员工
employeeManager.deleteEmployee(2);
// 查找员工
Employee employee = employeeManager.findEmployee(1);
System.out.println(employee);
}
阅读全文