• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing and looking up a string with variable number of fields  RSS feed

 
Silver Hawk
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to read a file and store the values and then later do a lookup.

For e.g., the file will look as follows:


I need to store these (I was thinking of a map). Later, I need to process every character and lookup this map to assign them points. Suppose I encounter Harry, I know that he's from Gryffindor and he's wearing a blue cloak. I will have to lookup this map (or whatever object I use) as


which should return me nothing. I then need to fall back to just the name and lookup


that should return me a 10.

Similarly, if I lookup for Ron, (suppose he's wearing black),


should return nothing, fall back to


again nothing, fall back to


which should return 5.

What will be an elegant way to store and read this data? I was thinking of using a map for storing the key value pairs and then a switch case to read them back. How would you do it?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, that sounds like a homework assignment if I ever saw one.

When you have done some actual work/coding on it and reached a spot that doesn't do what you expect, post some code.

I will give one bit of advice - start drawing diagrams of logic flow and "play computer'

Bill
 
Flaz Four
Greenhorn
Posts: 7
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to read data from the file using Java Properties API. For storing and processing this data in memory I would like to use tree.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!