473,382 Members | 1,435 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 1775
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bo Wisén | last post by:
Hi, A project in VB6 recently worked without any problems but now it's complaining when I try to use 'Right$'. In immediate mode, when I'm typing 'print left$("123456",2)' I get the correct...
12
by: Ted Mencini | last post by:
When I replaced older <IMG ALIGN=RIGHT ...> tags with a CSS definition <IMG class=right ...> xxx.css: IMG.right { BORDER: 0; align: right } I notice that the effect is NOT the same....
22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
2
by: Dr. Richard E. Hawkins | last post by:
I've googled around, and asked everyone I know, but I still can't find any reference to anyone else having faced this particular IE bug with floats. I've put a page at...
22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
3
by: deanfamily11 | last post by:
Ok, here's another problem I'm having. I've tried several different things, but I just can't get anything to be right justified. Any thoughts? #include <iostream> #include <iomanip>...
19
by: ashkaan57 | last post by:
Hi, I have a page in a right-to-left language and I am trying to make some bulleted lists using <ul>, but it puts the bullets to the left. Is there any way I can set the bullets to be on the...
5
by: tshad | last post by:
I have a datagrid that I cannot get to right justify a money amount (which is just a label). No matter what I do - it still right justifies it. <asp:TemplateColumn Visible="true"...
12
by: Dio1080 | last post by:
Ok, I need help on a for loop nested program using for loops, I'm trying to use a patten that goes like this: 123456 12345 1234 123 12 1 but when I try it, it goes like this: 123456
3
by: happyse27 | last post by:
Hi All, I wanted to align the text box for user registration but the code just wont budge... Kindly advise what is wrong? Cheers... Andrew <HTML>
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.