ArraryList 食品仓库管理
程序中有众多警告,怎么解决
package text;
import
import
import java.util.ArrayList;
public class Demo1 {
public static void main(String[] args) throws Exception {
shipintguanli.Spgl shiping = new shipintguanli.Spgl();
BufferedReader sr = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("请按提示选择已下功能");
System.out.println("添加食品请按1");
System.out.println("查询食品信息请按2");
System.out.println("修改食品价格请按3");
System.out.println("删除食品请安4");
System.out.println("退出请安0");
String str = sr.readLine();
if (str.equals("1")) {
System.out.println("请输入食品编号:");
String bh = sr.readLine();
System.out.println("请输入食品名称: ");
String mc = sr.readLine();
System.out.println("请输入食品价格: ");
float jg = Float.parseFloat(sr.readLine());
shipintguanli.Sp sp = new shipintguanli.Sp(bh, mc, jg);
shiping.addsp(sp);
}
else if (str.equals("2")) {
System.out.println("请输入食品编号");
String bh = sr.readLine();
shiping.spxx(bh);
}
else if (str.equals("3")) {
System.out.println("请输入食品编号");
String bh = sr.readLine();
System.out.println("请输入新的食品价格: ");
float jg = Float.parseFloat(sr.readLine());
shiping.spjg(bh, jg);
}
else if (str.equals("4")) {
System.out.println("请输入食品编号");
String bh = sr.readLine();
shiping.delsp(bh);
}
else if (str.equals("0")) {
System.out.println("感谢您的使用,再见");
System.exit(0);
break;
}
else {
System.out.println("输入有误");
}
}
}
public static class Spgl {
private ArrayList aa = null;
public Spgl() {
aa = new ArrayList();
}
public void addsp(shipintguanli.Sp sp) {
aa.add(sp);
System.out.println("添加新食品成功!");
}
public void spxx(String bh) {
int i;
for (i = 0; i < aa.size(); i++) {
shipintguanli.Sp sp = (shipintguanli.Sp) aa.get(i);
if (sp.getBiaonhao().equals(bh)) {
System.out.println("该食品名称为: ");
System.out.println("食品编号: " + sp.getBiaonhao());
System.out.println("食品名称: " + sp.getMingcheng());
System.out.println("食品价格: " + sp.getJiage());
break;
}
}
if (i == aa.size()) {
System.out.println("对不起,无此食品!");
}
}
public void spjg(String bh, float jg) {
int i;
for (i = 0; i < aa.size(); i++) {
shipintguanli.Sp sp = (shipintguanli.Sp) aa.get(i);
if (sp.getBiaonhao().equals(bh)) {
sp.setJiage(jg);
System.out.println("修改食品价格成功!");
break;
}
}
if (i == aa.size()) {
System.out.println("对不起没有找到相应的食品,修改价格失败!");
}
}
public void delsp(String bh) {
int i;
if (aa.size() == 0) {
System.out.println("对不起,仓库中已经没有食品了!");
}
for (i = 0; i < aa.size(); i++) {
shipintguanli.Sp sp = (shipintguanli.Sp) aa.get(i);
if (sp.getBiaonhao().equals(bh)) {
aa.remove(i);
System.out.println("删除食品成功!");
}
}
//这条if语句运行不出来,怎么解决
if ((i == aa.size()) && (aa.size() != 0)) {
System.out.println("对不起没有该食品!");
}
}
}
public static class Sp {
private String biaonhao;
private String mingcheng;
private Float jiage;
public String getBiaonhao() {
return biaonhao;
}
public void setBiaonhao(String biaonhao) {
this.biaonhao = biaonhao;
}
public String getMingcheng() {
return mingcheng;
}
public void setMingcheng(String mingcheng) {
this.mingcheng = mingcheng;
}
public Float getJiage() {
return jiage;
}
public void setJiage(Float jiage) {
this.jiage = jiage;
}
@Override
public String toString() {
return "Sp{" +
"biaonhao='" + biaonhao + '\'' +
", mingcheng='" + mingcheng + '\'' +
", jiage=" + jiage +
'}';
}
}
}