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

From Progzoo
Jump to: navigation, search
(Move dog 3)
(King's cross rent)
Line 101: Line 101:
  
 
</prog>
 
</prog>
 +
<answer>
 +
static void doIt(Document d){
 +
  Element parent = (Element) d.getElementById("kings-cross").getParentNode();
 +
  if (parent.getNodeName() == "bank") {System.out.println("0");}
 +
  else {
 +
 +
    int count = parent.getElementsByTagName("station").getLength();
 +
 +
    switch (count) {
 +
      case 1:  System.out.println("25"); break;
 +
      case 2:  System.out.println("50"); break;
 +
      case 3:  System.out.println("150"); break;
 +
      case 4:  System.out.println("400"); break;
 +
    }
 +
  }
 +
}
 +
</answer>
 
</question>
 
</question>
  

Revision as of 13:23, 19 December 2007

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>

How many properties?

Show the number of properties held by player "ship" (count only property - not stations)


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

Move dog 3

Player dog throws a 3. Give the label of the square he will land on.



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

Light blues

If one player holds all properties that are light-blue then give the id of that player. Otherwise give "none".


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

King's cross rent

State the amount due in rent if you land on kings-cross.If the owner of kings-cross has 1 station pay 25, if he has 2 stations pay 50, if 3 stations then 150, if 4 stations pay 200. If the station is owned by the bank pay 0.



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

Dog buys property

Player "dog" throws a 5, lands on a property and buys it. Update the game document to reflect the new state of play.


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