Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_58546982
Java_282566
提交
2dfb0d8a
J
Java_282566
项目概览
qq_58546982
/
Java_282566
与 Fork 源项目一致
Fork自
inscode / Java
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Java_282566
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2dfb0d8a
编写于
5月 09, 2023
作者:
6
64576273ecd7b40dc29f15d9
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tue May 9 10:26:00 UTC 2023 inscode
上级
5b0ce43e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
208 addition
and
5 deletion
+208
-5
Main.java
Main.java
+208
-5
未找到文件。
Main.java
浏览文件 @
2dfb0d8a
class
Main
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello world!"
);
}
}
\ No newline at end of file
package
kucun2
;
import
java.util.ArrayList
;
import
java.util.Scanner
;
//创建一个上商店类
public
class
Shop
{
//主方法 主要实现集合创建、调用商品初始化、调用菜单方法、调用序号选择方法
public
static
void
main
(
String
[]
args
)
{
//创建ArrayList集合,存储商品类型,存储数据类型FruitItem类型
ArrayList
<
FruitItem
>
array
=
new
ArrayList
<
FruitItem
>();
//调用商品初始化方法,传递集合
init
(
array
);
while
(
true
){
//调用菜单方法
mainMenu
();
//调用用户选择序号方法
int
choose
=
chooseFunction
();
switch
(
choose
)
{
case
1
:
//调用1: 货物清单
showFruitList
(
array
);
break
;
case
2
:
//2: 添加货物
addFruit
(
array
);
break
;
case
3
:
//3: 删除货物
showFruitList
(
array
);
deleteFruit
(
array
);
break
;
case
4
:
//4: 修改货物
showFruitList
(
array
);
updateFruit
(
array
);
break
;
case
5
:
//5: 退出
quit
(
array
)
;
return
;
default
:
System
.
out
.
println
(
"您输入的序号不在列表内"
);
break
;
}
}
}
//商品初始化方法。创建方法,将商品添加到集合里去。
public
static
void
init
(
ArrayList
<
FruitItem
>
array
){
//创建出多个FruitItem类型,并且属性赋值
FruitItem
f1
=
new
FruitItem
();
f1
.
ID
=
10001
;
//编号
f1
.
name
=
"水密桃"
;
f1
.
price
=
12.7
;
//价格
FruitItem
f2
=
new
FruitItem
();
f2
.
ID
=
10002
;
f2
.
name
=
"西瓜"
;
f2
.
price
=
12
;
FruitItem
f3
=
new
FruitItem
();
f3
.
ID
=
10003
;
f3
.
name
=
"哈密瓜"
;
f3
.
price
=
50.6
;
//创建的3个FruitItem类型变量,存储到集合中
array
.
add
(
f1
);
array
.
add
(
f2
);
array
.
add
(
f3
);
}
//主菜单
public
static
void
mainMenu
(){
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
(
"============================================"
);
System
.
out
.
println
(
"请您输入要操作的功能序号:"
);
}
//序号选择
public
static
int
chooseFunction
(){
Scanner
sc
=
new
Scanner
(
System
.
in
);
return
sc
.
nextInt
();
}
//库存货物查询
public
static
void
showFruitList
(
ArrayList
<
FruitItem
>
array
){
System
.
out
.
println
();
System
.
out
.
println
(
"----------商品库存清单----------"
);
System
.
out
.
println
(
"商品编号"
+
"\t"
+
"商品名称"
+
"\t"
+
"商品单价"
);
//遍历集合
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++){
//集合get方法,获取出每个FruitItem变量,可以使用FruitItem接受get结果
FruitItem
item
=
array
.
get
(
i
);
//变量item调用类中属性
System
.
out
.
println
(
item
.
ID
+
"\t"
+
item
.
name
+
"\t"
+
item
.
price
);
}
}
//添加新货物
public
static
void
addFruit
(
ArrayList
<
FruitItem
>
array
){
System
.
out
.
println
(
"您选择的是添加商品功能"
);
//创建Scanner变量
Scanner
sc
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"请您输入商品的编号:"
);
//输入商品的编号
int
ID
=
sc
.
nextInt
();
//输入商品的名字
System
.
out
.
println
(
"请输入商品的名字"
);
String
name
=
sc
.
next
();
//输入商品的单价
System
.
out
.
println
(
"输入商品的单价"
);
double
price
=
sc
.
nextDouble
();
while
(
price
<
0
)
{
System
.
out
.
println
(
"您输入的商品价格不合法,请您再次输入:"
);
price
=
sc
.
nextInt
();
}
//创建FruitItem变量
FruitItem
item
=
new
FruitItem
();
//item.属性赋值
item
.
ID
=
ID
;
item
.
name
=
name
;
item
.
price
=
price
;
array
.
add
(
item
);
System
.
out
.
println
(
"商品添加成功"
);
}
//删除货物
public
static
void
deleteFruit
(
ArrayList
<
FruitItem
>
array
){
System
.
out
.
println
(
"您选择的是删除功能"
);
System
.
out
.
println
(
"请您输入商品的编号"
);
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
ID
=
sc
.
nextInt
();
//遍历集合
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++){
//获取到每个FruitItem变量
FruitItem
item
=
array
.
get
(
i
);
//变量,调用属性ID,和用户输入的编号比较
if
(
item
.
ID
==
ID
){
//移除集合中的元素
//集合的方法remove实现
array
.
remove
(
i
);
System
.
out
.
println
(
"删除成功"
);
return
;
}
}
System
.
out
.
println
(
"你输入的编号不存在"
);
}
//修改货物
public
static
void
updateFruit
(
ArrayList
<
FruitItem
>
array
){
System
.
out
.
println
(
"您选择的是修改功能"
);
System
.
out
.
println
(
"请您输入商品的编号:"
);
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
ID
=
sc
.
nextInt
();
//遍历集合,获取每个FruitItem变量
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++){
FruitItem
item
=
array
.
get
(
i
);
//获取FruitItem的属性ID,和用户输入的ID比较
if
(
item
.
ID
==
ID
){
//
System
.
out
.
println
(
"输入新的商品编号:"
);
item
.
ID
=
sc
.
nextInt
();
System
.
out
.
println
(
"输入新的商品名字:"
);
item
.
name
=
sc
.
next
();
System
.
out
.
println
(
"输入新的商品价格:"
);
item
.
price
=
sc
.
nextDouble
();
while
(
item
.
price
<
0
)
{
System
.
out
.
println
(
"您输入的商品价格不合法,请您再次输入:"
);
item
.
price
=
sc
.
nextInt
();
}
System
.
out
.
println
(
"商品修改成功"
);
return
;
}
}
System
.
out
.
println
(
"您输入的编号不存在"
);
}
//退出系统
public
static
void
quit
(
ArrayList
<
FruitItem
>
array
){
System
.
out
.
println
(
"您已退出库存系统,欢迎下次使用······"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录