功能需求
管理员 快递录入 1、快递柜位置“由系统产生,且不能重复"。 2、快递单号"通过控制台输入"。 3、快递公司"通过控制台输入"。 4、6位取件码“由系统产生,且不能重复"。 删除快递(根据快递单号) 修改快递(根据快递单号) 查看所有快递(遍历)用户 快递取出 1、根据输入的取件码显示快递信息。 2、从快递柜中移除这个快递
Demo操作界面:
public class Demo {
@SuppressWarnings("resource")
public static void main(String
[] args
) throws InterruptedException
{
Admin admin
= new Admin();
User user
= new User();
System
.out
.println("┌────────────────────┐");
System
.out
.print("|");
for(int i
=0;i
<14;i
++)
{
System
.out
.print("██");
if(i
<5) {
Thread
.sleep(300);
i
++;
}
if(i
>10) {
Thread
.sleep(200);
i
++;
}
else{
Thread
.sleep(100);
}
}
System
.out
.println("|");
System
.out
.println("└────────────────────┘");
System
.out
.println(" 欢迎进入小区快递管理系统");
while(true) {
int k
= 0;
System
.out
.println("┏━━━━━━登录身份选择━━━━━┓");
System
.out
.println("┃ 1. 普通用户 ┃");
System
.out
.println("┃━━━━━━━━━━━━━━━━━━━┃");
System
.out
.println("┃ 2. 管理员 ┃");
System
.out
.println("┃━━━━━━━━━━━━━━━━━━━┃");
System
.out
.println("┃ 3. 退出系统 ┃");
System
.out
.println("┗━━━━━━━━━━━━━━━━━━━┛");
select();
Scanner input
= new Scanner(System
.in
);
int Identity
= input
.nextInt();
if(Identity
==3) {
System
.exit(0);
}
System
.out
.print("请输入登录账号:");
String count
= input
.next();
System
.out
.print("请输入登录密码:");
int password
= input
.nextInt();
System
.out
.print("登录中");
for(int i
=0;i
<10;i
++) {
Thread
.sleep(100);
System
.out
.print(".");
}
System
.out
.println();
if(Identity
==1) {
if(count
.equals("123456") && password
==123456) {
System
.out
.println(" 【登录成功】");
while(true) {
System
.out
.println("┏━━━━━━用户功能选择━━━━━┓");
System
.out
.println("┃ 1. 快递取出 ┃");
System
.out
.println("┃━━━━━━━━━━━━━━━━━━━┃");
System
.out
.println("┃ 2. 返回 ┃");
System
.out
.println("┗━━━━━━━━━━━━━━━━━━━┛");
select();
switch(input
.nextInt()) {
case 1:
user
.takePackage();
break;
case 2:
k
= 1;
break;
default:break;
}
if(k
==1) {
break;
}
}
}else {
System
.out
.println(" 【登录失败】");
}
}else if(Identity
==2) {
if(count
.equals("admin") && password
==123456) {
System
.out
.println(" 【登录成功】");
while(true) {
System
.out
.println("┏━━━━━━管理功能选择━━━━━┓");
System
.out
.println("┃ 1. 快递录入 ┃");
System
.out
.println("┃━━━━━━━━━━━━━━━━━━━┃");
System
.out
.println("┃ 2. 删除快递 ┃");
System
.out
.println("┃━━━━━━━━━━━━━━━━━━━┃");
System
.out
.println("┃ 3. 修改快递 ┃");
System
.out
.println("┃━━━━━━━━━━━━━━━━━━━┃");
System
.out
.println("┃ 4. 查看快递 ┃");
System
.out
.println("┃━━━━━━━━━━━━━━━━━━━┃");
System
.out
.println("┃ 5. 返回 ┃");
System
.out
.println("┗━━━━━━━━━━━━━━━━━━━┛");
select();
switch(input
.nextInt()) {
case 1://增
admin
.add();
break;
case 2://删
System
.out
.print("请输入快递单号:");
admin
.delete(input
.nextInt());
break;
case 3:
System
.out
.print("请输入快递单号:");
admin
.update(input
.nextInt());
break;
case 4://查
admin
.select();
break;
case 5://返回上一界面
k
= 1;
break;
default:break;
}
if(k
==1) {
break;
}
}
}else {
System
.out
.println(" 【登录失败】");
}
}else {
System
.out
.println("您输入的指令有误!");
}
}
}
public static void select() throws InterruptedException
{
System
.out
.print("请");
Thread
.sleep(100);
System
.out
.print("选");
Thread
.sleep(100);
System
.out
.print("择");
Thread
.sleep(100);
System
.out
.print(":");
}
}
Admin管理员权限:
public class Admin extends Package{
public static Object
[] elemt1
= new Object[10];
private int i
= 0;
public static Object
[] getElemt1() {
return elemt1
;
}
public static void setElemt1(Object
[] elemt1
) {
Admin
.elemt1
= elemt1
;
}
public int getI() {
return i
;
}
public void setI(int i
) {
this.i
= i
;
}
@SuppressWarnings("resource")
public void add() throws InterruptedException
{
Package p
= new Package();
Package p1
= new Package();
Random r
= new Random();
int k1
= 1;
int k2
= 1;
int num
= 0;
int code
= 0;
while(k1
==1) {
k1
= 0;
num
= r
.nextInt(100);
for(int i
=0;i
<elemt1
.length
;i
++) {
p1
= (Package
)elemt1
[i
];
if(elemt1
[i
]!=null
) {
if(num
==p1
.getPositionId()) {
k1
=1;
break;
}
}
}
}
p
.setPositionId(num
);
System
.out
.print("请输入快递单号:");
Scanner input
= new Scanner(System
.in
);
p
.setNumber(input
.nextInt());
System
.out
.print("请输入快递公司:");
p
.setCompeny(input
.next());
while(k2
==1) {
k2
= 0;
code
= r
.nextInt(899999)+100000;
for(int i
=0;i
<elemt1
.length
;i
++) {
p1
= (Package
)elemt1
[i
];
if(elemt1
[i
]!=null
) {
if(code
==p1
.getCode()) {
k2
=1;
break;
}
}
}
}
p
.setCode(code
);
elemt1
[i
] = p
;
System
.out
.print("正在为您生成订单");
for(int i
=0;i
<10;i
++) {
Thread
.sleep(100);
System
.out
.print(".");
}
System
.out
.println();
select();
i
++;
}
public void delete(int number
) {
int j
= 0;
for(int i
=0;i
<elemt1
.length
;i
++) {
Package p1
= new Package();
p1
= (Package
)elemt1
[i
];
if(elemt1
[i
]!=null
) {
if(number
==p1
.getNumber()) {
j
= i
;
}
}
}
for(;j
<i
;j
++) {
elemt1
[j
] = elemt1
[j
+1];
}
elemt1
[i
] = null
;
i
--;
}
public void update(int number
) {
for(int i
=0;i
<elemt1
.length
;i
++) {
Package p1
= new Package();
p1
= (Package
)elemt1
[i
];
if(elemt1
[i
]!=null
) {
if(number
==p1
.getNumber()) {
System
.out
.print("请更改新的快递单号:");
@SuppressWarnings("resource")
Scanner input
= new Scanner(System
.in
);
p1
.setNumber(input
.nextInt());
System
.out
.print("请更改新的快递公司:");
p1
.setCompeny(input
.next());
elemt1
[i
] = p1
;
}
}
}
}
public void select() {
int isExist
= 0;
for(int i
=0;i
<elemt1
.length
;i
++) {
if(elemt1
[i
]!=null
) {
System
.out
.println(elemt1
[i
]);
isExist
= 1;
}
}
if(isExist
==0) {
System
.out
.println("==包裹不存在==");
}
}
}
User用户权限:
public class User{
@SuppressWarnings("resource")
public void takePackage() {
Admin a
= new Admin();
System
.out
.print("请输入取件码:");
Scanner input
= new Scanner(System
.in
);
int code
= input
.nextInt();
int isExist
= 0;
for(int i
=0;i
<Admin
.elemt1
.length
;i
++) {
Package p1
= new Package();
p1
= (Package
)Admin
.elemt1
[i
];
if(Admin
.elemt1
[i
]!=null
) {
if(code
==p1
.getCode()) {
System
.out
.println(p1
);
a
.delete(p1
.getNumber());
isExist
= 1;
}else {
isExist
= 1;
}
}
}
if(isExist
==0) {
System
.out
.println("==包裹不存在==");
}
}
}
Package快递包裹:
package pers
.sheng
.demo
;
public class Package {
private int positionId
;
private int number
;
private String compeny
;
private int code
;
public Package() {
super();
}
public Package(int positionId
, int number
, String compeny
, int code
) {
super();
this.positionId
= positionId
;
this.number
= number
;
this.compeny
= compeny
;
this.code
= code
;
}
public int getPositionId() {
return positionId
;
}
public void setPositionId(int positionId
) {
this.positionId
= positionId
;
}
public int getNumber() {
return number
;
}
public void setNumber(int number
) {
this.number
= number
;
}
public String
getCompeny() {
return compeny
;
}
public void setCompeny(String compeny
) {
this.compeny
= compeny
;
}
public int getCode() {
return code
;
}
public void setCode(int code
) {
this.code
= code
;
}
public String
toString() {
return "┏━━━━━━快递包裹信息━━━━━┓\n"+" 快递位置编号:"+positionId
+"\n┃━━━━━━━━━━━━━━━━━━━┃"+"\n 快递单号 :"+number
+"\n┃━━━━━━━━━━━━━━━━━━━┃"+"\n 快递公司:"+compeny
+"\n┃━━━━━━━━━━━━━━━━━━━┃"+"\n 取件码:"+code
+"\n┗━━━━━━━━━━━━━━━━━━━┛";
}
}
运行结果:
转载请注明原文地址:https://ipadbbs.8miu.com/read-52931.html