Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860
Holodeck Design Project - Huben's Wiki

Holodeck Design Project

From Huben's Wiki
Jump to: navigation, search
Line 25: Line 25:
 
* To keep it simple, all methods have no arguments and return strings with the class name and the method name, such as "Dragon flame".  If a method is inherited, you can just use the inherited method: no need to override the method.
 
* To keep it simple, all methods have no arguments and return strings with the class name and the method name, such as "Dragon flame".  If a method is inherited, you can just use the inherited method: no need to override the method.
 
* Use the following class to see your results.
 
* Use the following class to see your results.
 +
 +
<pre>
 +
public class Holodeck
 +
{
 +
  public static void main(String[] args)
 +
  {
 +
    Horse h = new Horse();
 +
    Elephant e = new Elephant();
 +
    Pegasus p = new Pegasus();
 +
    Dumbo d = new Dumbo();
 +
    Dragon r = new Dragon();
 +
 +
    // Replace the XXX with the appropriate class or interface for each line.
 +
    // The line should compile and the print() later on should not have errors either.
 +
    // XXX should be a type that gives a method such as fly().
 +
    // This should demonstrate polymorphism: each object knows its own methods.
 +
    XXX[] eared = {e, d};            // classes with ears()
 +
    XXX[] hooved = {h, p};          // classes with hooves()
 +
    XXX[] grazers = {h, e, p, d};  // classes with graze()
 +
    XXX[] fliers = {p, d, r};          // classes with fly()
 +
   
 +
    System.out.print("ears():  ");
 +
    for (int i = 0; i < eared.length; i++)
 +
      System.out.print(eared[i].ears() + "    ");
 +
    System.out.println();
 +
   
 +
    System.out.print("hooves():  ");
 +
    for (int i = 0; i < hooved.length; i++)
 +
      System.out.print(hooved[i].hooves() + "    ");
 +
    System.out.println();
 +
 +
    System.out.print("graze():  ");
 +
    for (int i = 0; i < grazers.length; i++)
 +
      System.out.print(grazers[i].graze() + "    ");
 +
    System.out.println();
 +
 +
    System.out.print("fly():  ");
 +
    for (int i = 0; i < fliers.length; i++)
 +
      System.out.print(fliers[i].fly() + "    ");
 +
    System.out.println();
 +
  }
 +
}
 +
</pre>

Revision as of 18:55, 24 January 2013

Personal tools
translate