Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Design and implement a C# class for items that can be sold via a point-of-sale system for a coffee shop. Design and implement at least two other classes derived from your first class. Each class must have at least one method and at least two attributes. Make sure your derived classes add additional attributes and/or methods. Write a sample application that is either console- or forms-based that instantiates one of each of your objects and use the ToString method (defined by default for all C# objects) to output meaningful data for each of your classes as they are instantiated. Instantiate that class via your console application and display (via a ToString method that you implement) the details of that object.

I have no idea how to go about this any help would be appreciated?
Posted
Updated 25-Jan-14 13:37pm
v2
Comments
Ravi Bhavnani 25-Jan-14 19:42pm    
If you have absolutely no idea how to go about this, I suggest you take another look at your class notes. Then, if you have questions about implementing specific facets of this assignment, post your code along with your question and we'll try and help you. But don't expect someone else to attend class and study on your behalf.

/ravi
Garth J Lancaster 25-Jan-14 19:48pm    
'oops' - I was in the process of typing up a starter :-(
Ravi Bhavnani 25-Jan-14 19:52pm    
Actually I was just about to commend you on your effort! I personally think the OP won't benefit from your reply and is fishing for codez.

/ravi

Well ... take a pad and pencil, start thinking about the data and Types

You have an Item

So, you have an Item Name - String ?, Item Price - Double, Quantity Left - Integer .. (for example)

You'll need to think about wether these should be public, private (to your Item Class for instance), and wether you need to use get/set for example

Then think about what operations you'd have - 'Items' are sold arnt they - so maybe you'd have a method for 'selling' an item - that would take a quantity of how many units are being sold and throw some sort of error if the requested quantity is more than the quantity left

You already have a clue to one method you'll need - ToString()

So, I'd start with maybe

C#
public Class Item
{
    public String  itemName {get; set;}
    public Decimal itemPrice {get; set;}
    public Int     itemQuantityLeft {get; set;}

    public override String ToString()
    {
        String readableItem = 
            String.Format(
                "Name {0} Price {1} Quantity Left {2}",
                itemName, itemPrice, itemQuantityLeft);
        return readableItem;
    }
}


but that's a 30sec starter - you need to implement a constructor, the method for Selling an Item, .... seems you have a lot of reading to do
 
Share this answer
 
v2
Comments
PIEBALDconsult 25-Jan-14 20:01pm    
"Item Price - Double"

No! Integer! Don't use floating point types for non-floating point values.
Garth J Lancaster 25-Jan-14 20:04pm    
ok, one can use integer if that represents 'cents' - eg 250 = $2.50 - but I did say a) he'd have to think about his data type(s), b) it was a 30s example
Garth J Lancaster 25-Jan-14 20:05pm    
... that would be the least of the OP's issue
BillWoodruff 25-Jan-14 21:38pm    
Why not use decimal; it's a 128 bit value type specifically meant for financial transactions, currency calculations, etc.
Garth J Lancaster 25-Jan-14 22:11pm    
I went back and changed it to decimal - I probably meant 'decimal' when I thought of a simple type, but whacked double out in the example - if it were me, personally, I'd probably be using a fully fledged money class
see the hole problem is the course I am taking uses the head first into C# 2nd edition book, and problems assigned for me to do, the book absolutely gives me no help. the first week was to design a console that says hello world which was easy, the second week was to design a program a day at the races, which was just crazy, may bee I should just drop this class thanks for all your help everyone.
 
Share this answer
 
Comments
Ravi Bhavnani 25-Jan-14 19:56pm    
Have you approached your instructor for assistance? It seems what you need is more instruction about the basics of object oriented design. Unfortunately that's not something that's easy to convey in a few lines in a forum post.

/ravi
Member 10549049 25-Jan-14 20:02pm    
Thanks for the reply Ravi, I feel like I need to learn more of the basic's and maybe this class is to much for me, it just seems seems it started out OK, now it seems it jumped up to fast for me to understand.
Ravi Bhavnani 25-Jan-14 20:12pm    
Check out Pluralsight @ http://pluralsight.com/training/courses. The courses "C# From Scratch" and "C# From Scratch Part 2" may be the best coin you'll spend on learning how to program in C#. I highly recommend them.

/ravi
Ravi Bhavnani 25-Jan-14 20:17pm    
Check out this 5 minute tutorial from Lynda.com: http://www.youtube.com/watch?v=SS-9y0H3Si8.

/ravi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900