473,396 Members | 1,738 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,396 software developers and data experts.

Creating a TreeMap within a TreeMap.

2
I am trying to create a tree map within a TreeMap.
Any help would be great.
goes a bit like this:

Expand|Select|Wrap|Line Numbers
  1. public class ChessImpl implements CHESS
  2. {
  3.     private Map<String, Integer> name;
  4.     private int membernumber;
  5.     private Map<String, Map<Integer, Holding>> stock;
  6.     private Map<Integer, Holding> intSearch;
  7.     private Holding holder;
  8.  
  9.  
  10.     public ChessImpl()
  11.     {
  12.         name = new TreeMap<String, Integer>();
  13.         membernumber = 1;
  14.         stock = new TreeMap<String, Map<Integer, Holding>>();
  15.     }
  16.  
With the stock map do I need to create another map before i insert it?
Main problem is when i use the put method it wont accept it?

Expand|Select|Wrap|Line Numbers
  1.     public void issue(String stockCl, String client, int nshares)
  2.     {
  3.         if(name.containsKey(client) && (nshares > 100))
  4.         {
  5.         Holding holder = new Holding(stockCl, client, nshares);
  6. int memNum = name.get(client);
  7.   stock.put(stockCl, (memNum, holder)) //THIS IS WHERE IM HAVING THE MAJOR PROBLEM
  8.         }
  9.         else
  10.         {
  11.             System.out.println("Client name has not been created or the amount of shares is less than 100");
  12.         }
  13.  
I keep getting a error message. this is the holding class just for refrence.

Expand|Select|Wrap|Line Numbers
  1. public class Holding  
  2. {
  3.  
  4.     private String stock;
  5.     private String client;
  6.     private int shares;
  7.     public Holding(String stock, String client, int shares)
  8.     {
  9.         this.stock = stock; 
  10.         this.client = client; 
  11.         this.shares = shares;
  12.     }
  13.  
Sep 17 '07 #1
3 2869
JosAH
11,448 Expert 8TB
I keep getting a error message.
What is the exact error message? Is it a compilation error or a runtime error?

kind regards,

Jos
Sep 17 '07 #2
Nepomuk
3,112 Expert 2GB
I am trying to create a tree map within a TreeMap.
Any help would be great.
goes a bit like this:

Expand|Select|Wrap|Line Numbers
  1. public class ChessImpl implements CHESS
  2. {
  3.     private Map<String, Integer> name;
  4.     private int membernumber;
  5.     private Map<String, Map<Integer, Holding>> stock;
  6.     private Map<Integer, Holding> intSearch;
  7.     private Holding holder;
  8.  
  9.  
  10.     public ChessImpl()
  11.     {
  12.         name = new TreeMap<String, Integer>();
  13.         membernumber = 1;
  14.         stock = new TreeMap<String, Map<Integer, Holding>>();
  15.     }
  16.  
With the stock map do I need to create another map before i insert it?
Main problem is when i use the put method it wont accept it?

Expand|Select|Wrap|Line Numbers
  1.     public void issue(String stockCl, String client, int nshares)
  2.     {
  3.         if(name.containsKey(client) && (nshares > 100))
  4.         {
  5.         Holding holder = new Holding(stockCl, client, nshares);
  6. int memNum = name.get(client);
  7.   stock.put(stockCl, (memNum, holder)) //THIS IS WHERE IM HAVING THE MAJOR PROBLEM
  8.         }
  9.         else
  10.         {
  11.             System.out.println("Client name has not been created or the amount of shares is less than 100");
  12.         }
  13.  
I keep getting a error message. this is the holding class just for refrence.

Expand|Select|Wrap|Line Numbers
  1. public class Holding  
  2. {
  3.  
  4.     private String stock;
  5.     private String client;
  6.     private int shares;
  7.     public Holding(String stock, String client, int shares)
  8.     {
  9.         this.stock = stock; 
  10.         this.client = client; 
  11.         this.shares = shares;
  12.     }
  13.  
Quick answer: Yes, you must create an Object, before using it. Instead of
Expand|Select|Wrap|Line Numbers
  1. stock.put(stockCl, (memNum, holder));
  2.  
you want something like
Expand|Select|Wrap|Line Numbers
  1. TreeMap tmpMap = new TreeMap();
  2. tmpMap.put(memNum, holder);
  3. stock.put(stockCl, tmpMap);
  4.  
That should do the job.

Greetings,
Nepomuk
Sep 17 '07 #3
millz
2
Thanks for the suggestions ill try that code 2nite.
Sep 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark Wayne | last post by:
Is is possible to use TreeMap in the javascript <SCRIPT> portion of HTML? If so, how? Thanks, mark
4
by: Nick | last post by:
Hi, I have a windows application, wherein the solution consists of 5 projects. When I try to create a setup and deployment project for this solution, I'm somehow unable to add anything in...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
1
by: treeman | last post by:
I copied the example Compile is successful .net 2003 but i press button , nothing to show but the example has box show up, why ? where 's wrong?
0
by: Treeman | last post by:
I copied the example Compile is successful .net 2003 but i press button , nothing to show but the example has box show up, why ? where 's wrong?
0
by: Thiero | last post by:
I am a studend in programming and I find it difficult to use treemap, can any one help me on how to use treemap. Specially the purpose is to use treemap and give a list of students firstname...
5
by: Dan | last post by:
Hi, I use the <asp:CreateUserWizardcontrol for creating memberusers. In that windows, one must provide an emailaddress. My question is: how can an user later change his emailaddress? Thanks...
1
by: twdo | last post by:
OK. I am totally frustrated here. I have a setup project within Visual Studio. That setup project is calling a class library project by the use of Custom Actions. Within that class library (my...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.