import java.util.*;
public class Shiping {
private int Spid;
private String Spname;
private int Spmoney;
public Shiping(int Spid,String Spname,int Spmoney){
this.Spid=Spid;
this.Spname=Spname;
this.Spmoney=Spmoney;
}
public Shiping(){
}
public int getSpid() {
return Spid;
}
public void setSpid(int spid) {
Spid = spid;
}
public String getSpname() {
return Spname;
}
public void setSpname(String spname) {
Spname = spname;
}
public int getSpmoney() {
return Spmoney;
}
public void setSpmoney(int spmoney) {
Spmoney = spmoney;
}
public String toString(){
return "食品编号:"+Spid+"\n"+"食品名称:"+Spname+"\n"+"食品价格:"+Spmoney+"\n";
}
public static void main(String[] args) {
// Shiping sp=new Shiping();
Chuli cl=new Chuli();
cl.mian();
}
}
class Chuli{
Scanner sc=new Scanner(System.in);
ArrayList al=new ArrayList();
ArrayList a2=new ArrayList();/Pst集合类
private int i;
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public Chuli(){
}
Shiping sp=new Shiping();
public void addSp(){
System.out.println("请输入食品编号:");
int bianhao=sc.nextInt();
System.out.println("请输入食品名称:");
String name=sc.next();
System.out.println("请输入食品价格");
int money=sc.nextInt();
a2.add("1"+bianhao);
System.out.println("1"+bianhao);
al.add(new Shiping(bianhao,name,money));
Shiping sp2=(Shiping) al.get(i);
System.out.println("食品添加成功");
System.out.println("食品编号:"+sp2.getSpid());
System.out.println("食品名称:"+sp2.getSpname());
System.out.println("食品价格:"+sp2.getSpmoney());
System.out.println();
int z=this.getI()+1;
this.setI(z);
}
public void found(){
System.out.println("请输入要查找食品编号:");
int i=sc.nextInt();
try{
for(int x=0;x>=0;x++){
if(a2.get(x).equals("1"+i)){
System.out.println(al.get(x));
break;
}
} }catch(IndexOutOfBoundsException e){
System.out.println("没有此产品");
}
}
public void change(){
System.out.println("请输入要修改食品编号:");
int i=sc.nextInt();
try{
for(int x=0;x>=0;x++){
if(a2.get(x).equals("1"+i)){
System.out.println(al.get(x));
Shiping sp2=(Shiping) al.get(x);
System.out.println("请输入修改后的价格:");
int z=sc.nextInt();
sp2.setSpmoney(z);
System.out.println(al.get(x));
break;
}
}
}catch(IndexOutOfBoundsException e){
System.out.println("没有此产品");
}
}
public void shanchu(){
System.out.println("请输入要删除的产品编号:");
int i=sc.nextInt();
try{
for(int x=0;x>=0;x++){
if(a2.get(x).equals("1"+i)){
//System.out.println("1"+i);
al.remove(x);
a2.remove(x);
System.out.println("已成功删除该产品");
break;
}
} }catch(IndexOutOfBoundsException e){
System.out.println("没有此产品");
}
}
public void show(){
for(int x=0;x<a2.size();x++){
System.out.println(al.get(x)+"\n");
}
}
public void mian(){
while(true){
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("退出系统请按0");
try{
int i=sc.nextInt();
if(i==1){
this.addSp();
}else if(i==2){
this.found();
}else if(i==3){
this.change();
}else if(i==4){
this.shanchu();
}else if(i==5){
this.show();
}else if(i==0){
System.out.println("已成功退出系统");
break;
}else if(i<0||i>4){
System.out.println("输入有误");
}
}catch(InputMismatchException e){
System.out.println("请输入正确数字");
break;
}
}
}
}
这个算不算面向对象编程