Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java tree map trouble
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Lorna Robinson
Java tree map trouble
0 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


This is a project for a class, and I am totally stuck! I've created a tree map using an input text file. I split the lines into fields so that I could work with 2 elements from the file. It appears to display correctly, but I'm getting an "ArrayIndexOutOfBoundsException: 3" error, and I'm not getting anything returned to my Set. I just can't seem to wrap my brain around this one...can someone take a look at my code and point me in the right direction please?

  [code]
  public static Set<String> agentValue(String inputFileName)
    throws FileNotFoundException
 {
     Set<String> tail = new TreeSet<String>();
     SortedMap<String, Number> agentValues = new TreeMap<String, Number>();
     Scanner in = new Scanner(new File(inputFileName));
 String line = inputFileName;
 String[] fields;

   while (in.hasNextLine())
   {
     line = in.nextLine();
 fields = line.split("\\s");
     String agentId = (fields [3]); 
 Double pValue = Double.parseDouble(fields [2]);

     if (agentValues.containsKey(agentId))
        {
    pValue += agentValues.get(agentId).intValue();
        }
     agentValues.put(agentId, pValue);


 // Create keyMap with all keys and values
        Set<String> keySet = agentValues.keySet();
        for (String key : keySet)
        {
        Number value = agentValues.get(key);
        System.out.println(key + " : " + value);

        tail.add(key + " : " + value);
        }

   }
   return tail;
   }
  [/code]

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Java tree map trouble
Java tree map trouble  This is a project for a class, and I am totally stuck! I've created a tree map using an input text file. I split the lines into fields so that I could work with 2 elements from the file. It appears
Trouble in running Dos Command from Java Servlet
Trouble in running Dos Command from Java Servlet  Hello All, I have to run following command from Java. The command is : vscanwin32 /S C:\Test > C... 'cmd /c dir /s'. Looking forward for the help. -Java Beginner
Advertisements
Building a Binary Tree using std::map, std:set
Building a Binary Tree using std::map, std:set  Hi, can someone please explain to me how I can make use of std::map and/or std::set to create... to represent a binary tree because I can't help but to see that map and set act
Tree Map Example
TreeMapExample.java C:\vinod\collection>java TreeMapExample Tree Map... Tree Map Example     ...(String[] args) { System.out.println("Tree Map Example!\n"); TreeMap <
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three condition such as x<5,5<=x<10 and 10<=x<15 after that we have
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
Java Map Example
Java Map Example  How we can use Map in java collection?   The Map interface maps unique keys to value means it associate value to unique...(String[] args) { Map mp = new HashMap(); mp.put(new Integer(2
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
tree view - Java Beginners
tree view  I want to use tree view in my example code to display data... visit the following links: http://www.roseindia.net/java/example/java/swing/TreeComponent.shtml http://www.roseindia.net/java/example/java/swing
java tree expressions - XML
java tree expressions  hi all, i have a problem in tree expressions. see there is a document tree like a parent document has no. of child... code to solve the problem and visit to : http://www.roseindia.net/java
tree view - Java Beginners
tree view  Hello Deepak, Thanks for your help last time regarding java. I have another problem, Actually I want a tree...   Hi Friend, You are using jsp or java swing. Please clarify this. Do
Java Map iterator with example
Java Map Iterator is an interface. It keeps the data in the key and value form. It is implemented by HashMap, Tree Map. Map has no iterator method. So...() method to get the data in Set object form. Java Map Iterator with Example
Java Map
Java Map         In Java, a Map is a kind of generalized array. It provides a more general way of storing elements. It is an object that maps keys to values. Map
tree view - Java Beginners
tree view   I m using swing for the treeview in my application and also the database(Hsqldb). I want to connect the tree view with the database fields. If u want more clarification ,let me know. Thanks
Tree
Tree  print("code sample");1) Write Java code to create the following tree using new Tree state- ments: 1
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
Java map building - Development process
Java map building  Hello All I want to build a map for a road... to proceed further i need to build a map using these coodinates which i am unable to think of how to do it. I can only use java swing or 2d for this purpose. Any
Map Java Objects with Database tables
Map Java Objects with Database tables  How to map Java Objects with Database tables?   First write Java domain objects ie. beans with setter and getter methods. Then map java class to table and database columns to Java
B+ tree - Java Beginners
. In this assignment, you will implement B+-tree data structure on a fixed-length data... field is separated or delimited by a white space. Initially, your B+-tree... user interface (GUI). Your GUI also visualizes B+tree structure after executing any
map
map  using map, i want display message based on id selected [both are strings]   i do no   Hi Friend, Try the following code...) { Map map=new HashMap(); map.put("Message1","Hello
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
Trouble with array manipulation
Trouble with array manipulation  For this project I have to print 10 random numbers from (0-99), print the max value, the average of the ten numbers... 16 14 68 80 23 This is the code i attempted, but i am having trouble putting
B+tree lodaing - Java Beginners
B+tree lodaing  hi, i have fixed-length data file such student table. All fields are fixed length: 8 for number (20022509), 3 for name (PIS), 4... or delimited by a white space. how i can Initially, constructed B+ tree based
Tree View with database - Java Beginners
Tree View with database   Hi, I'm working with Swing.I have...); JTree tree = new JTree(parent); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION
tree
tree  hi.i want search in bstree . what am i doing?   Please visit the following link: http://www.roseindia.net/tutorial/java/core/binarySearch.html
drawing a christmas tree - Java Beginners
drawing a christmas tree  how do i write a program that draws a chrimas tree using the knowledge of loops only. i.e * *** ***** ******* the program will draw a Christ mas tree  Hi ChristmasTree.javaimport java.awt.
Using Arraylist or Hash Map - Java Interview Questions
Using Arraylist or Hash Map  what could b the pros and cons changing between Hash Map to Array List
Advertisements
 

 

 

DMCA.com