用JAVA编写一个程序,模拟库存管理系統。该系統主要包话系统首页、商品入库、商品显示和删除商品功能。 实现思路: (1)定义仓库货物类,对象定义私有属性,包括商品type,brand,id,price和number。 (2)在仓库管理类中,定义集合,存储供品对象。 (3)主方法中为集合添加初始化的数据,采用无线循环的方式显示菜单栏,用if...else语句判断用户索要进行的操作,用户可以键盘输入0,1, 2,3来选择对应的燥作,如果输入0退出程序;如果输入1可以进行商品入库;输入2可以显示库房内所有商品;输入3可以删除进行商品出库,如果是其他输入则提示用户操作失败。 (4)定义商品入库的方法,选择后首先是提示用户是否录入商品,输入no 不录入商品,直按退出并显示所有商品。输入其他任何数据开始录入商品并提示健盘编入什么,录入完毕后退出并显示所有商品, (5)定义显示仓库所有商品的方法,用Iterator迭代器的方法循环遍历集合打印,实现商品显示。
时间: 2023-11-13 11:04:39 浏览: 224
jisuanqi,java项目实例源码,java进销存管理系统
好的,下面是Java代码实现:
仓库货物类:
```java
public class Goods {
private String type;
private String brand;
private String id;
private double price;
private int number;
public Goods(String type, String brand, String id, double price, int number) {
this.type = type;
this.brand = brand;
this.id = id;
this.price = price;
this.number = number;
}
public String getType() {
return type;
}
public String getBrand() {
return brand;
}
public String getId() {
return id;
}
public double getPrice() {
return price;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
@Override
public String toString() {
return "type='" + type + '\'' +
", brand='" + brand + '\'' +
", id='" + id + '\'' +
", price=" + price +
", number=" + number;
}
}
```
仓库管理类:
```java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class Warehouse {
private ArrayList<Goods> goodsList;
public Warehouse() {
this.goodsList = new ArrayList<Goods>();
}
public void init() {
goodsList.add(new Goods("手机", "华为", "001", 3999.0, 10));
goodsList.add(new Goods("电脑", "联想", "002", 7999.0, 5));
goodsList.add(new Goods("平板", "苹果", "003", 4999.0, 8));
}
public void addGoods() {
System.out.println("是否录入商品?(yes/no)");
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
if (input.equals("no")) {
return;
}
System.out.println("请输入商品类型(type):");
String type = scanner.next();
System.out.println("请输入商品品牌(brand):");
String brand = scanner.next();
System.out.println("请输入商品编号(id):");
String id = scanner.next();
System.out.println("请输入商品价格(price):");
double price = scanner.nextDouble();
System.out.println("请输入商品数量(number):");
int number = scanner.nextInt();
goodsList.add(new Goods(type, brand, id, price, number));
System.out.println("已成功添加商品!");
}
public void showGoods() {
Iterator<Goods> iterator = goodsList.iterator();
while (iterator.hasNext()) {
Goods goods = iterator.next();
System.out.println(goods);
}
}
public void deleteGoods() {
System.out.println("请输入商品编号(id):");
Scanner scanner = new Scanner(System.in);
String id = scanner.next();
Iterator<Goods> iterator = goodsList.iterator();
while (iterator.hasNext()) {
Goods goods = iterator.next();
if (goods.getId().equals(id)) {
iterator.remove();
System.out.println("已成功删除商品!");
return;
}
}
System.out.println("未找到该商品!");
}
}
```
主方法:
```java
public class Main {
public static void main(String[] args) {
Warehouse warehouse = new Warehouse();
warehouse.init();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:\n0.退出程序\n1.商品入库\n2.商品显示\n3.删除商品");
int choice = scanner.nextInt();
switch (choice) {
case 0:
System.out.println("程序已退出!");
System.exit(0);
break;
case 1:
warehouse.addGoods();
break;
case 2:
warehouse.showGoods();
break;
case 3:
warehouse.deleteGoods();
break;
default:
System.out.println("操作失败!");
break;
}
}
}
}
```
这个程序实现了模拟库存管理系统的功能,包括商品入库、商品显示和删除商品功能。
阅读全文