【发布时间】:2016-05-17 22:51:50
【问题描述】:
我需要创建一个 SETTER method within Class B 来为存储在定义的数组中的特定 Product 对象设置新价格A类。 任何人都可以帮助这个基本的java代码吗? 假设我们创建了苹果产品,我们需要更改它的价格。 我需要使用类似的东西:
setPrice (product name, price);
这里是场景:
Class A
public class Store(){
Store(Product aProduct){
products = new ArrayList< Product> ();
}
}
Class B
private String name;
private int price;
public class Product {
Product ( String aName, int aPrice) {
name = aName;
price = aPrice;
}
}
非常感谢。
【问题讨论】:
-
许多可能性。有什么特殊要求吗?
-
另外,为什么商店会采用不使用的产品
aProduct?类B是Product吗?
标签: java arrays methods setter