| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 438 人关注过本帖
标题:Java菜鸟遇到困难了
只看楼主 加入收藏
陈恒
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-7-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
Java菜鸟遇到困难了

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单词的有错误 我的文件名也是这个
搜索更多相关主题的帖子: private public return import super 
2015-07-07 12:34
陈恒
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-7-7
收藏
得分:0 
谁能帮我看一下  谢谢了
2015-07-07 12:47
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:20 
// 输入商品信息方法
public static ArrayList<Produce> Input() {

剑栈风樯各苦辛,别时冰雪到时春
2015-07-07 14:23
快速回复:Java菜鸟遇到困难了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015463 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved