Difference between revisions of "DOM Tutorial Monopoly Questions (Easy)"

From Progzoo
Jump to: navigation, search
(Number of child elements)
(Number of player elements)
Line 49: Line 49:
 
<p class='imper'>Print the number of player elements.</p>
 
<p class='imper'>Print the number of player elements.</p>
  
<prog>static void doIt(Document d){
+
<prog>static void doIt(Document d)
 +
{
 
   System.out.println(d.getDocumentElement());
 
   System.out.println(d.getDocumentElement());
 
}
 
}
Line 55: Line 56:
  
 
</prog>
 
</prog>
<answer>static void doIt(Document d){
+
<answer>static void doIt(Document d)
 +
{
 
   System.out.println(d.getElementsByTagName("player")
 
   System.out.println(d.getElementsByTagName("player")
 
                       .getLength());
 
                       .getLength());

Revision as of 20:52, 12 September 2012

These question concern the monopoly documents. Your code is tested against three different documents http://progzoo.net/monopoly1.xml http://progzoo.net/monopoly2.xml and http://progzoo.net/monopoly3.xml

<!DOCTYPE game SYSTEM "monopoly.dtd">
<game>
 <board>
  <square label='GO'>
   <player id='dog'  cash='1500'/>
   <player id='ship' cash='1500'/>
   <player id='iron' cash='1500'/>
  </square>
  <square label='Old Kent Road' ref='old-kent-road'/>
  <square label='Community Chest'/>
  <square label='Whitechapel' ref='whitechapel'/>
  <square label='Income Tax (Pay 200)'/>
  <square label="King's Cross Station" ref='kings-cross'/>
 </board>
 <bank>
  <property id='old-kent-road' price='60'  colour='brown'/>
  <property id='whitechapel'   price='60'  colour='brown'/>
  <station  id='kings-cross'   price='200'/>
 </bank>
</game>

Number of child elements

Show the number of child elements.


[Font] [Default] [Show] [Resize] [History] [Profile]

Number of player elements

Print the number of player elements.



[Font] [Default] [Show] [Resize] [History] [Profile]

Square 3

Show the label of square element number 3.



[Font] [Default] [Show] [Resize] [History] [Profile]

Parent of player 1

Show the label of the parent of player number 1.



[Font] [Default] [Show] [Resize] [History] [Profile]

id of property 0

Show the id of property number 0.



[Font] [Default] [Show] [Resize] [History] [Profile]