❔ HI i need some help create this function
public class Game
{
private List<Product> _products = new List<Product>();
public List <Product> Products => _products;
private Product _selectedProduct;
private int i = 0;
public Game()
{
Product product1 = new Product("IPhone 14",1400,"iphone.png");
Product product2 = new Product("Xiaomi 15",1000,"xiaomi.png");
Product product3 = new Product("FairLife Milk",6,"fairlifemilk.png");
Product product4 = new Product("Air Pods Max",500,"airpodsmax.png");
Product product5 = new Product("Tootsie Rolls",20,"tootsieroll.png");
PopulateProductList(product1);
PopulateProductList(product2);
PopulateProductList(product3);
PopulateProductList(product4);
PopulateProductList(product5);
}
public Product SelectedProduct
{
get
{
return _selectedProduct;
}
set
{
_selectedProduct = value;
}
}
private void PopulateProductList(Product product)
{
_products.Add(product);
}
public Product GetNextProduct()
{
}
//Get the price of the selected product (ReadOnly)
private int GetCurrentProductPrice()
{
return _selectedProduct.Price;
}
//Using Enum
public CheckStatus CheckGuesses( int guessedprice)
{
if (_selectedProduct.Price == guessedprice )
return CheckStatus.Correct;
else if (_selectedProduct.Price > guessedprice)
return CheckStatus.TooHigh;
else
return CheckStatus.TooLow;
}
}
}
9 Replies
The method should select a product from the products list and return a copy of that product to the caller.
i. Note that the price of the returned product should be changed to zero (otherwise the caller can check the price).
ii. The method should also save the picked product in the private variable _selectedProduct so the class can check validate the user guesses in the CheckGuess method.
the method name is GetNextProduct()
Ok. So what's the question?
create a method to this
No, we're not going to do your homework
well it not going for grade but its just pratice he assigned
Suggest you... practise then
that function is the only problem im having
If you can be more specific that will get better feedback
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.