注册 登录
编程论坛 JAVA论坛

Java菜鸟遇到困难了

陈恒 发布于 2015-07-07 12:34, 438 次点击

import java.util.ArrayList;
import java.util.Scanner;
  
public class Produce {
 private String name;
 private int count;
 private int price;
  
 public Produce() {
 super();
 }
  
 public Produce(String name, int count, int price) {
 super();
 this.name = name;
 this.count = count;
 this.price = price;
 }
  
 public String getName() {
 return name;
 }
  
 public void setName(String name) {
 this.name = name;
 }
  
 public int getCount() {
 return count;
 }
  
 public void setCount(int count) {
 this.count = count;
 }
  
 public int getPrice() {
 return price;
 }
  
 public void setPrice(int price) {
 this.price = price;
 }
  
 // 输入商品信息方法
 public static ArrayList<> Input() {
 Scanner sc = new Scanner(System.in);
 ArrayList<Produce> al = new ArrayList<Produce>();
 String name;
 int count, price;
 System.out.println("输入商品名称:");
 name = sc.nextLine();
 System.out.println("输入商品数量:");
 count = sc.nextInt();
 System.out.println("输入商品单价:");
 price = sc.nextInt();
 al.add(new Produce(name, count, price));
 System.out.println("添加商品成功");
 return al;
 }
  
 // 查看
 public static void Find(String name, ArrayList<Produce> al) {
 for (Produce p : al) {
 if (name.equals(p.getName())) {
 System.out.println("你要查看的商品是:" + p.getName() + " 数量是:"
 + p.getCount() + " 单价是:" + p.getPrice() + " 总价是:"
 + (p.getCount() * p.getPrice()));
 }
 }
 }
   
 // 删除某个商品
 public static void Del(String name, ArrayList<Produce> al){
 for(int i = 0; i < al.size(); i++){
 if(name.equals(al.get(i).getName())){
 System.out.println("删除商品[" + al.get(i).getName() + "]成功");
 al.remove(i);
 break;
 }
 }
 }
  
 public static void main(String[] args) {
 ArrayList<Produce> al = new ArrayList<Produce>();
 al = Input();// 添加
 Scanner sc = new Scanner(System.in);
 System.out.println("输入要查看的商品名:");
 String fname = sc.next();
 Find(fname, al);
 System.out.println("输入要删除的商品名:");
 String dname = sc.next();
 Del(dname, al);
 }
}
为什么一直提示所有包含这个Produce单词的有错误 我的文件名也是这个
2 回复
#2
陈恒2015-07-07 12:47
谁能帮我看一下  谢谢了
#3
林月儿2015-07-07 14:23
// 输入商品信息方法
public static ArrayList<Produce> Input() {
1