• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with my assignment  RSS feed

 
Chas Martin
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks, I am here again to see if you guys can help me with an assignment. I have came here for help before and you guys helped me immensely. I have this assignment:
A file containing information about fruits is structured as follows. <fruit>
<type> Apple </type>
<color> Green </color>
</fruit>
<fruit>
<color> Yellow </color>
<type> Banana </type>
</fruit>
The file consists of tags and data. An opening and closing tag pair, <tag> ... </tag>, define a particular data element. Each fruit has a type and a color. Notice that either may appear first within the <fruit> ... </fruit> tags. Your program should read a file called �fruit.txt� with the above structure.
The output of your program should be the number of each type of fruit, and the total pieces of fruit. For example, the output using the lines above is:
Number of type Apple: 1
Number of type Banana: 1
Total pieces of fruit: 2
Your program should be flexible enough to handle a file containing an indeterminate number of fruit descriptions. However, you may assume that there will be no more than 100 different types of fruit.


I am not asking anyone to do this for me, I know how this place works. I've been looking at the problem trying to figure out where to even start and I've hit a wall already. I was just wondering where I should start. I am awfully confused as to how to get it to read the file and then perform the operations required. What method should I use? Any hints will be great to get me rollin.
Thanks guys
This is where Im at so far ----->
 
Thomas Young
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an example here that might help you:
http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html

Regards,
TY.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!