d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help With C# > Offer Fg
Add Reply New Topic New Poll
Member
Posts: 1,886
Joined: Mar 17 2011
Gold: 6,080.00
Apr 26 2013 08:36pm
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
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 26 2013 09:22pm
make Q a getter imo

List<Coffee> sortedInventory = inventory.OrderBy(order => order.Q).ToList();

Quote
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

sounds like you want more of a "contains" method that returns true/false as opposed to a "find"

boolean exists = mylist.Contains(myneworder);

something like that anyway.

This post was edited by carteblanche on Apr 26 2013 09:28pm
Member
Posts: 33,568
Joined: Mar 3 2007
Gold: 2,090.85
May 12 2013 11:05pm
I can do this if you can send me the original lab requirements.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll