Hey all,
I am having some trouble with my last business project in C# class. I'll try to explain what I need done and the code I have written already. The purpose of the program is to calculate various values around ordering quantities of coffee supplies, given inputs such as Demand, Cost, etc.
The trouble I am having is, I have created a 'List' using a base class Coffee type and need to Sort this List based on a method called 'Q' which computes a value based on the inputs. See below for details:
List<Coffee> inventory = new List<Coffee>(); // Created the List
Then I've asked for the inputs using a comma delimited separation, I parsed the data using Split and then validate the data as being a positive number or valid in context using a Method I created.
At this point, is where I can't figure out how to:
1) Sort the List based on their computed 'Q' values as its a Method, example being, say the first object.Q computes to 200, next object.Q is 150. I need the lower amount Q to be at the first index of the List (inventory), and need to be able to sort at least 10 if needed.
2) I need to also implement a 'Find' method that will use an overridden 'Equals' method to see if any new objects will be a complete duplicate of any current ones in the List
Here are the data members I am using in the base class Coffee and derived class Regular. I also have a derived class Decaf but it has no needed values for the above problems.
public class Coffee
{
private float demand;
private float holdcost;
private string brand;
private float ucost;
--below those are get/set methods for demand and ucost--
public class Regular : Coffee
{
private RoastType rtype;
public enum RoastType { light = 1, medium, dark };
Specific to the Regular type of Coffee is RoastType which the user inputs a number to describe its type.
In Decaf and Regular sub classes I have over ridden the Q method, so when I call it from inventory[i].Q it computes the associated Q for that class. So how do I use Find, Equals, and CompareTo?
I can give more details or explanations to anyone who thinks they can help with those problems I mentioned. I will gladly tip with fg for a solution
This post was edited by SlayTheBot on Apr 26 2013 08:37pm