471,334 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 software developers and data experts.

Is this right?

J-T
Is there a problem of defining a category object like below. I am just
trying to create a proof-of-concept sort of application (and I don't want to
use database) , so I have to sort of hard code the data.
public class Category
{
private static SortedList m_CategoryCollection;
public static SortedList CategoryCollection
{

get
{
m_CategoryCollection = new SortedList();
m_CategoryCollection.Add("Foods",0);
m_CategoryCollection.Add("Books",0);
m_CategoryCollection.Add("Medcine",0);
m_CategoryCollection.Add("others",0.01);
return (m_CategoryCollection);
}

}
}

Thanks in advance
Feb 10 '06 #1
3 1703
Hi,
I can't really say if this is correct because I don't really know what it is
that you are trying to accomplish. About the code, why reinitalize the list
each time you access it? Have a look at the modified version below.
public class Category
{
private static SortedList m_CategoryCollection;
public static SortedList CategoryCollection
{

get
{
if( m_CategoryCollection == null )
{
m_CategoryCollection = new SortedList();
m_CategoryCollection.Add("Foods",0);
m_CategoryCollection.Add("Books",0);
m_CategoryCollection.Add("Medcine",0);
m_CategoryCollection.Add("others",0.01);
}

return (m_CategoryCollection);
}

}
}

Sayed Ibrahim Hashimi
www.sedodream.com
"J-T" wrote:
Is there a problem of defining a category object like below. I am just
trying to create a proof-of-concept sort of application (and I don't want to
use database) , so I have to sort of hard code the data.
public class Category
{
private static SortedList m_CategoryCollection;
public static SortedList CategoryCollection
{

get
{
m_CategoryCollection = new SortedList();
m_CategoryCollection.Add("Foods",0);
m_CategoryCollection.Add("Books",0);
m_CategoryCollection.Add("Medcine",0);
m_CategoryCollection.Add("others",0.01);
return (m_CategoryCollection);
}

}
}

Thanks in advance

Feb 10 '06 #2
Hi J-T,
if you want some kind of data persistence without resorting to a database,
then I would recommend some kind of file based system using XML as your
datastore. This will allow you to modify your data in the file without
having to change your code and recompile. Plus XML parsing / searching and
manipulating are all very well supported by the .Net language.

With regards to your issue, are you seeing changes you make the the
collection being lost. If so this is probably because you are creating a new
instance of the collection each time, you should modify your code like Sayed
mentioned.

Hope that helps
Mark Dawson
http://www.markdawson.org

"J-T" wrote:
Is there a problem of defining a category object like below. I am just
trying to create a proof-of-concept sort of application (and I don't want to
use database) , so I have to sort of hard code the data.
public class Category
{
private static SortedList m_CategoryCollection;
public static SortedList CategoryCollection
{

get
{
m_CategoryCollection = new SortedList();
m_CategoryCollection.Add("Foods",0);
m_CategoryCollection.Add("Books",0);
m_CategoryCollection.Add("Medcine",0);
m_CategoryCollection.Add("others",0.01);
return (m_CategoryCollection);
}

}
}

Thanks in advance

Feb 10 '06 #3
J-T
Thank you all ,
As I mentioned this is just a proof of concept sort of project and data
never gets changed .That's why I decided to hard code the data in that
way.What I am trying to do is to create a collection of pre-defined products
and print it for user and then he choose the product id from the list I
print for him and enters the quantities and at the end I am going to print a
reciept which includes sales tax and imported tax.here is what I am going to
develope:

Basic sales tax is applicable at a rate of 10% on all goods, except books,
food, and medical products that are exempt. Import duty is an additional
sales tax applicable on all imported goods at a rate of 5%, with no
exemptions.

When I purchase items I receive a receipt which lists the name of all the
items and their price (including tax), finishing with the total cost of the
items, and the total amounts of sales taxes paid. The rounding rules for
sales tax are that for a tax rate of n%, a shelf price of p contains (np/100
rounded up to the nearest 0.05) amount of sales tax.

I have to Write an application that prints out the receipt details for these
shopping baskets...

INPUT:

Input 1:

1 book at 12.49

1 music CD at 14.99

1 chocolate bar at 0.85

Input 2:

1 imported box of chocolates at 10.00

1 imported bottle of perfume at 47.50

Input 3:

1 imported bottle of perfume at 27.99

1 bottle of perfume at 18.99

1 packet of headache pills at 9.75

1 box of imported chocolates at 11.25

OUTPUT

Output 1:

1 book : 12.49

1 music CD: 16.49

1 chocolate bar: 0.85

Sales Taxes: 1.50

Total: 29.83

Output 2:

1 imported box of chocolates: 10.50

1 imported bottle of perfume: 54.65

Sales Taxes: 7.65

Total: 65.15

Output 3:

1 imported bottle of perfume: 32.19

1 bottle of perfume: 20.89

1 packet of headache pills: 9.75

1 imported box of chocolates: 11.85

Sales Taxes: 6.70

Total: 74.68
I have created three class for it ,one is Product calss ,the other one is
Category class and the third one is ProductCollection. Am I doing this
right?

Thanks for your valuable time.

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
Hi J-T,
if you want some kind of data persistence without resorting to a
database,
then I would recommend some kind of file based system using XML as your
datastore. This will allow you to modify your data in the file without
having to change your code and recompile. Plus XML parsing / searching
and
manipulating are all very well supported by the .Net language.

With regards to your issue, are you seeing changes you make the the
collection being lost. If so this is probably because you are creating a
new
instance of the collection each time, you should modify your code like
Sayed
mentioned.

Hope that helps
Mark Dawson
http://www.markdawson.org

"J-T" wrote:
Is there a problem of defining a category object like below. I am just
trying to create a proof-of-concept sort of application (and I don't want
to
use database) , so I have to sort of hard code the data.
public class Category
{
private static SortedList m_CategoryCollection;
public static SortedList CategoryCollection
{

get
{
m_CategoryCollection = new SortedList();
m_CategoryCollection.Add("Foods",0);
m_CategoryCollection.Add("Books",0);
m_CategoryCollection.Add("Medcine",0);
m_CategoryCollection.Add("others",0.01);
return (m_CategoryCollection);
}

}
}

Thanks in advance

Feb 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Bo Wisén | last post: by
22 posts views Thread by Marek Mand | last post: by
2 posts views Thread by Dr. Richard E. Hawkins | last post: by
22 posts views Thread by Simon | last post: by
3 posts views Thread by deanfamily11 | last post: by
19 posts views Thread by ashkaan57 | last post: by
5 posts views Thread by tshad | last post: by
12 posts views Thread by Dio1080 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.