Reputation: 57
What I need to override or to do, to find the object by "Product Name" and the search function can work on an array of my objects, like this products.FindByName ("Корпус вагона")
public class Main {
public static void main(String[] args) {
Products [] products = new Products[]{
new Products("Корпус вагона","431-221","20Г1ФЛ",3001.5),
new Products("Турбина пароперегревателя","131-321","09Х14Н16Б",278.4),
new Products("Турбинные диски","231-521","10Х11Н20Т3Р",62.7),
new Products("Компенсационный проводов","431-221","МН16",12.7),
new Products("Железнодорожная рельса","431-221","М76ВТ",350.1),
};
products.FindByName("products")//Use like this,how it do?
}
}
class Products {
private String _productName;
private String _productCode;
private String _brandMetal;
private double _weight;
public Product FindByName(string nameOfProduct)
{
}
}
Upvotes: 0
Views: 26
Reputation: 159096
You need 2 classes: The Product
class to store the attributes of a single product in fields, and a Products
class to manage the collection of products.
The Product
class will have the constructor you've used in the main
method.
The Products
class will have two methods: add(Product)
and findByName(String)
.
I'll leave it up to you to code this.
Upvotes: 1