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

From Progzoo
Jump to: navigation, search
(Light blues)
(King's cross rent)
Line 107: Line 107:
 
<p class='imper'>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.</p>
 
<p class='imper'>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.</p>
  
<prog>static void doIt(Document d){
+
<prog>static void doIt(Document d)
 +
{
 
   System.out.println(d.getDocumentElement());
 
   System.out.println(d.getDocumentElement());
 
}
 
}
Line 114: Line 115:
 
</prog>
 
</prog>
 
<answer>
 
<answer>
static void doIt(Document d){
+
static void doIt(Document d)
 +
{
 
   Element parent = (Element) d.getElementById("kings-cross").getParentNode();
 
   Element parent = (Element) d.getElementById("kings-cross").getParentNode();
   if (parent.getNodeName() == "bank") {System.out.println("0");}
+
   if (parent.getNodeName() == "bank")
   else {
+
  {
 
+
    System.out.println("0");
 +
  }
 +
   else
 +
  {
 
     int count = parent.getElementsByTagName("station").getLength();
 
     int count = parent.getElementsByTagName("station").getLength();
  
     switch (count) {  
+
     switch (count)  
 +
    {  
 
       case 1:  System.out.println("25"); break;
 
       case 1:  System.out.println("25"); break;
 
       case 2:  System.out.println("50"); break;
 
       case 2:  System.out.println("50"); break;

Revision as of 20:56, 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>

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]