猿问

方法setsp无法使用?

package 学生成绩管理;


import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;


class Sp {

private String bianhao;

private String mingcheng;

private double jiage;

Sp(String bianhao,String mingcheng,double jiage)

{

this.bianhao=bianhao;

this.mingcheng=mingcheng;

this.jiage=jiage;

}

public String getBianhao() {

return bianhao;

}

public void setBianhao(String bianhao) {

this.bianhao = bianhao;

}

public String getMingcheng() {

return mingcheng;

}

public void setMingcheng(String mingcheng) {

this.mingcheng = mingcheng;

}

public double getJiage() {

return jiage;

}

public void setJiage(double jiage) {

this.jiage = jiage;

}

}

class Spg

{

ArrayList<Object> aa=null;

Scanner in=null;

Spg()

{

aa=new ArrayList();

in=new Scanner(System.in);

}

public void addsp(Sp Sp)

{

aa.add(Sp);

System.out.println("增加成功");

}

public void spxx(String bh)

{

int i;

int c=aa.size();

for(i=0;i<c;i++)

{

Sp sr=(Sp)aa.get(i);

if(sr.getBianhao().equals(bh))

{

System.out.println("信息如下:");

System.out.println("食品编号:"+sr.getBianhao());

System.out.println("食品名称:"+sr.getMingcheng());

System.out.println("食品价格:"+sr.getJiage());

}

}

if(i==c)

{

System.out.println("输入有误");

}

}

public void delsp(String bh)

{

int i;

if(aa.size()==0)

{

System.out.println("没有信息");

}

for(i=0;i<aa.size();i++)

{

Sp sr=(Sp)aa.get(i);

if(sr.getBianhao().equals(bh))

{

aa.remove(i);

}

}

if(i==aa.size()&&aa.size()!=0)

{

System.out.println("输入有误");

}

}

public void setsp(String bh)

{

int i;

for(i=0;i<aa.size();i++)

{

Sp sr=(Sp)aa.get(i);

if(sr.getBianhao().equals(bh))

{

System.out.println("请输入新的名称");

String c=in.next();

sr.setBianhao(c);

System.out.println("请输入新的价格");

double a=in.nextDouble();

sr.setJiage(a);

//aa.remove(i,bh);

}

}

if(i==aa.size()&&aa.size()!=0)

{

System.out.println("输入有误");

}

}

public void exitsp()

{

System.out.println("谢谢使用");

System.exit(0);

}

public void addsp(String bh, String mg, double jg) {

// TODO Auto-generated method stub

}

}

public class Lianxi2

{

public static void main(String []args) throws IOException

{

Spg gl=new Spg();

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 srt=sr.readLine();

if(srt.equals("1"))

{

System.out.println("请添加食品名称");

String mg=sr.readLine();

System.out.println("请添加食品编号");

String bh=sr.readLine();

System.out.println("请添加食品价格");

double jg=Double.parseDouble(sr.readLine());

gl.addsp(bh,mg,jg);

}else if(srt.equals("2"))

{

System.out.println("请输入食品编号");

String bh=sr.readLine();

gl.spxx(bh);

}else if(srt.equals("3"))

{

System.out.println("请输如食品编号");

String bh=sr.readLine();

gl.delsp( bh);

}else if(srt.equals("4"))

{

System.out.println("请输如食品编号");

String bh=sr.readLine();

gl.setsp( bh);这里的方法发现根本无法使用,求大神指点错误

}else if(srt.equals("0"))

{;

gl.exitsp( );

}

}

}

}


黄森huang
浏览 1474回答 1
1回答

ziom

这样一段长而臭的代码,还没有格式化,怎么看 - -
随时随地看视频慕课网APP

相关分类

Java
我要回答