Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 02-15-2005, 10:21 PM   #1 (permalink)
Crazy
 
[JAVA] Need to add 'double' to hashtable

Here is what i'm working with:

Code:
public class Menu1DB
{
    public static Hashtable loadMenu()
	{
        int i = 0;
	String line;
        Hashtable hshProdDesc = new Hashtable();
	Hashtable hshProdPrice = new Hashtable();
        StringTokenizer strings;
		try
		{
			BufferedReader file =
			new BufferedReader(new FileReader("menu.txt"));
			// priming read
			line = file.readLine();
			//while ((line = file.readLine()) != null)
			while (line != null)
			{
			strings = new StringTokenizer(line, ",");
			String strProdID = strings.nextToken();
			String strProdDesc = strings.nextToken();
			String strProdPrice = strings.nextToken();
			double dblProdPrice = Double.valueOf(strProdPrice).doubleValue();
			hshProdDesc.put(strProdID,strProdDesc);
//-->>	             hshProdPrice.put(strProdID,dblProdPrice);
Apparently '.put' only allows (Object, Object) so i'm stuck. I need to do (Object, double).

Thanks!

-BD
BoltedDown is offline  
Old 02-15-2005, 11:35 PM   #2 (permalink)
a-j
Tilted
 
The Double class is derived from object, you need to use that since Java 1.4- doesn't support putting primitives inside hashtables. Something like

Code:
String strProdPrice = strings.nextToken();
Double dblProdPrice = Double.valueOf(strProdPrice);
hshProdDesc.put(strProdID,dblProdDesc);
a-j is offline  
Old 02-16-2005, 05:20 PM   #3 (permalink)
Crazy
 
Location: The state of denial
a-j hit the nail on the head there. On a side note, it looks like you are adding both the product Id and the price under the same Hash table key. This won't work. Each item in a hash table needs to have a different key. Maybe you should make a "Product" class that holds all the information about a product (Description, Id and Price from what I can see) and store that in your Hash table.
__________________
Smoke me a kipper, I'll be back for breakfast.
madcow is offline  
 

Tags
add, double, hashtable, java

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 12:16 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38