Total Pageviews

Thursday, May 24, 2012

EXAM 1 COMPLETED

View Assessment Result: Exam 1 Multiple-Choice





What does "url" stand for?





(a)

5.00


  
   




In www.google.com; what does "www" stand for?





(b)

5.00


  
   




How do search engine companies like Google, Microsoft, and Yahoo make money?





(d)

5.00


  
   




What can be some unethical practices on the internet?





(c)

5.00


  
   




In the following URL, what is the name of the server? http://trestle.icarnegie.com/ssd1/course.html





(a)

5.00


  
   




HTML heading tags include which of the following?
  1. <H>
  2. <H1>
  3. <H8>






(d)

5.00


    See section 1.2.3, subsections "Headings, Horizontal Lines, and Preformatted Text," in the course notes.

   




Which of the following is a valid HTML segment that directs Web browsers to display green text?





(d)

5.00


    See section 1.2.3, subsection "Size and Color," of the course notes.

   




The <PRE> tag in HTML indicates the start of





(d)

5.00


    See section 1.2.3, subsections "Headings, Horizontal Lines, and Preformatted Text," of the course notes.

   




Which of the statements is true about the following HTML segment?
<a href="www/cnn.com">CNN news</a>






(d)

5.00


   See section 1.2.4 of the course notes.
   




Consider the following table.

Which of the following HTML sequences can be used to lay out the preceding table?






(c)

5.00


   See section 1.2.4 of the course notes.
   




Testing each element of your Web page as you add it has the effect of





(c)

5.00


   See section 1.2.6 of the course notes.
   




Which of the following path formats can be used to specify the value of the href attribute of the <a> tag?
  1. An absolute path
  2. A relative path






(a)

5.00


    See section 1.2.4 in the course notes.

   




What is the conceptual difference between logical and physical styles?





(c)

5.00


   See section 1.2.3 of the course notes.
   




Logical style tags in HTML include which of the following?
  1. <EM>
  2. <STRONG>
  3. <B>






(d)

0.00


    See section 1.2.3, subsections "Physical Styles and Logical Styles," of the course notes.

   




When a Web browser submits an HTML form to a Web server, the browser sends





(c)

5.00


   See section 1.3.3, subsection "Form Submission and Servlets," in the course notes.

   




In the name-value pairs that represent a submitted HTML form, names are separated from values by the character _____, and pairs are separated from one another by the character _____.





(d)

5.00


   See section 1.3.3, subsection "Form Submission and Servlets," in the course notes.

   




Which of the following statements is (are) true of Java servlets?
  1. They can produce dynamic responses to client requests.
  2. They are invoked directly by clients without involvement by a server.






(b)

0.00


   See section 1.3.2 in the course notes.

   




In an HTML FORM element, the values get and post are the only valid options for which of the following attributes?





(d)

5.00


   See section 1.3.1, subsection "The FORM Element," in the course notes.

   




Typically, a request from a client browser is forwarded to a servlet by a





(c)

0.00


   See section 1.3.2, subsection "An Overview of Servlets," in the course notes.

   




In the client-side mechanism client-pull, _____ are generated _____.





(b)

0.00


   See section 1.3.2, subsection "Server Push-Client Pull," in the course notes.

   



Go to top of assessment.


Tuesday, May 22, 2012

EX 8

EX 7

2 java files :  

1)catfish.java




import java.util.Vector;


/**
 * Catfish - simulates a catfish - can swim, eat, and consume
 * energy in the process.
 */
public class Catfish extends LivingBeing {

    /**
     * The catfish is born "alive".
     * Then it dies, becoming a corpse.
     */
    private static final String ALIVE = "alive";

    /**
     * Energy needed to swim in a block of time.
     */
    private static final int ENERGY_TO_SWIM = 2;
   
    /**
     * The catfish is born "alive".
     * Then it dies, becoming a "dead" corpse.
     */
    private static final String DEAD = "dead";

   
    /**
     * Lowest possible energy needed for a baby to survive.
     */
    private static final int BABY_MIN_ENERGY = 15;
   
    /**
     * Maximum energy that a baby can store.
     */
    private static final int BABY_MAX_ENERGY = 100;

   
    /**
     * Energy needed to look for food once.
     */
    private static final int ENERGY_TO_LOOK_FOR_FOOD = 1;
   
    /**
     * Energy expended to eat once.
     */
    private static final int ENERGY_TO_EAT = 1;
   
    // Concept example: final. since it is a constant
    // Concept example: static. since only one value is needed
    //                         irrespective of number of object instances
    /**
     * String constant - used to indicate the direction catfish is facing.
     */
    private static final String RIGHT = "right";

    /**
     * String constant - used to indicate the direction catfish is facing.
     */
    private static final String LEFT = "left";

    /**
     * String constant - used to indicate the direction catfish is facing.
     */
    private static final String UP = "up";

    /**
     * String constant - used to indicate the direction catfish is facing.
     */
    private static final String DOWN = "down";

    /**
     * Name of species
     */
    private static final String SPECIES = "Catfish";

    /**
     * Row-wise location of the catfish
     */
    private int row;

    /**
     * Column-wise location of the catfish
     */
    private int column;

    /**
     * Is the catfish dead or alive?
     */
    private String deadOrAlive;
   
    /**
     * Amount of energy the catfish has.
     */
    private int energy;

    /**
     * Age expressed as blocks of time lived
     */
    private int age = 0;

    /**
     * Name of this catfish.
     */
    private final String name;

    /**
     * The simulation to which this catfish belongs.
     * This is needed so the catfish can send a message
     * to simulation and ask
     * for prey (or predator) in the neighboring locations.
     * Prey is food. Food is good!
     */
    private Simulation simulation;

    /**
     * Minimum energy level needed to survive.
     * The minimum could increase as the individual grows.
     */
    private int minEnergy;
   
    /**
     * Maximum energy level that the catfish could carry.
     * The maximum could change as the individual grows.
     */
    private int maxEnergy;
   
    /**
     * Which direction am I facing.
     */
    private String direction;

    /**
     *
     * Number of Catfish created
     */
    private static int nCatfishCreated = 0;

    /**
     * Constructor. Initialize an catfish to start life at a specified
     * location with a specified energy. If location is out of bounds,
     * locate the catfish at the nearest edge.
     *
     * @param initialRow - the row at which the catfish is located
     * @param initialColumn - the column at which the catfish is located
     * @param initialSimulation - the simulation that the catfish belongs to
     */
    public Catfish(
        int initialRow,
        int initialColumn,
        Simulation initialSimulation) {

            name = SPECIES + nCatfishCreated;
           
            simulation = initialSimulation;
           
            deadOrAlive = ALIVE;
           
            row = initialRow;
            column = initialColumn;
           
            minEnergy = BABY_MIN_ENERGY;
            maxEnergy = BABY_MAX_ENERGY;
           
            age = 0;
            direction = RIGHT;
           
            do{
                energy = nextInt(BABY_MAX_ENERGY);
            }while(energy<BABY_MIN_ENERGY || energy>BABY_MAX_ENERGY);   
           
            ++nCatfishCreated;       
    }
   
    /**
     * Get the row at which the catfish is located
     *
     * @return - the row of the catfish's location.
     */       
    public int getRow() {
        return row;
    }

    /**
     * Get the column at which the catfish is located
     *
     * @return - the column of the catfish's location.
     */       
    public int getColumn() {
        return column;
    }

    /**
     * Get the catfish's age
     *
     * @return the age of the catfish expressed in blocks of time
     */
    public int getAge() {
        return age;
    }

    /**
     * Color of the catfish expressed in hex notation.
     * For example, the "green-est" color is "#00FF00",
     * "blue-est" is "#0000FF", the "red-est" is "#FF0000".
     *
     * @return the rgb color in hex notation. preceded by a pound character '#'
     */
    public String getColor() {
        return "#FFFFFF"; // default is white.
    }

    /**
     * Get the name of this catfish
     *
     * @return the name of the catfish.
     */
    public String getName() {
        return name;
    }
   
    /**
     * Get the minimum energy needed to live.
     *
     * @return the minimum energy needed for the catfish to live.
     */
    private int getMinEnergy() {
        return minEnergy;
    }
   
    /**
     * get the maximum energy that the catfish can carry.
     *
     * @return the maximum energy the catfish can carry.
     */
    private int getMaxEnergy() {
        return maxEnergy;
    }
   

    /**
     * Get the energy currently carried by the catfish.
     *
     * @return current energy level of the organism
     */
    public int getEnergy() {
        return energy;
    }

    /**
     * Sets energy level.
     * If new energy level is less than minimum energy level, the organism dies.
     * New energy level is capped at maximum energy level.
     */
    private void setEnergy(int newEnergy) {
        if (newEnergy<minEnergy)
        {
            die();
        }
        else
        {
            if(newEnergy>=maxEnergy)
            {
                energy = maxEnergy;
            }
            else
                energy = newEnergy;
        }
        energy = newEnergy;
       
    }

    /**
     * Die: Change the deadOrAlive to DEAD.
     */
    public void die() {
        deadOrAlive = DEAD;
    }

    /**
     * Is the catfish dead?
     *
     * @return <code>true</code> if dead. <code>false</code>, otherwise.
     */
    public boolean isDead() {
        return (deadOrAlive == DEAD);
    }

    /**
     * Get the direction faced by the catfish.
     *
     * @return the facing direction.
     */
    private String getDirection() {

        return direction;
    }

    /**
     * Is the catfish hungry?
     *
     * @return True, if hungry. False, otherwise.
     */
    private boolean isHungry() {
       
        // Hungry, if current energy level is less than twice the
        // amount needed for survival.
        if(energy >= minEnergy*2)
            return false;
        else{   
            return true;
        }
    }

    /**
     * Move the catfish to a new row, if new row is within lake bounds.
     *
     * @param newRow - the row to move to.
     * @return the row moved to. Lake boundary limits movement. -1, if dead.
     */
    private int moveToRow(int newRow) {
       
        if (newRow < row) direction = LEFT;
        if (newRow > row) direction = RIGHT;
        row = newRow;
        return row;
    }

    /**
     * Move the catfish to a new column, if new column is within lake bounds.
     *
     * @param newColumn - the column to move to.
     * @return the column moved to. Lake boundary limits movement.
     */
    private int moveToColumn(int newColumn) {
       
        if (newColumn < column) direction = DOWN;
        if (newColumn > column) direction = UP;
        column = newColumn;

        return column;
    }

    /**
     * This individual belongs to the Catfish species.
     * 
     * @return The string indicating the species
     */
    public String getSpecies() {
        return SPECIES;
    }

    /**
     * Catfish should be displayed as an image.
     *
     * @return a constant defined in {@link Simulation#IMAGE Simulation} class
     */
    public String getDisplayMechanism() {
        return Simulation.IMAGE;
    }

    /**
     * Get the image of the catfish
     *
     * @return filename of Catfish image
     */
    public String getImage() {
       
        if (direction == LEFT) return "/Catfish-left.gif";
        if (direction == RIGHT) return "/Catfish-right.gif";
        if (direction == UP) return "/Catfish-up.gif";
        if (direction == DOWN) return "/Catfish-down.gif";
       
        return "/Carfish-right.gif";
    }


    /**
     * Look for food in the neighborhood. Consume some energy in the process.
     *
     * @return a neighboring algae that is food.
     */
    private AlgaeColony lookForFoodInNeighborhood() {
        int neighborIndex;
        // Looking for food consumes energy.
        setEnergy(getEnergy() - ENERGY_TO_LOOK_FOR_FOOD);

        if (isDead()) {

            return null;
        }

        Vector neighbors =
            simulation.getNeighbors(getRow(), getColumn(), 1);

        for (neighborIndex = 0;
            neighborIndex < neighbors.size();
            ++neighborIndex) {
            if (neighbors.get(neighborIndex) instanceof AlgaeColony) {

                return (AlgaeColony) neighbors.get(neighborIndex);
            }
        }       
        return null;
    }

   

    /**
     * Catfish lives its life. It may lose or gain energy.
     */
    public void liveALittle() {
       
        if (energy<=minEnergy){
            die();
        }
        ++age;
       

        minEnergy += nextInt(5);
        maxEnergy += nextInt(5);
        swimIfPossible();
       
       
    }
    /**
     * Swim to a new location if possible.
     * Consumes some energy.
     */
     private void swimIfPossible() {
        
         if (energy>=0){
            energy = energy - ENERGY_TO_SWIM;   
        }
        moveToColumn(nextInt(10));
        moveToRow(nextInt(10));
       
     }
   
     public int nextInt(int limit){
         int a;
         a = (int)((double) Math.random()*limit);
         return a;
     }

}


==============================================
2) crocodile.java

import java.util.Vector;


/**
 * Crocodile - simulates a crocodile - can swim, eat, and consume
 * energy in the process.
 */
public class Crocodile extends LivingBeing {

    /**
     * The crocodile is born "alive".
     * Then it dies, becoming a corpse.
     */
    private static final String ALIVE = "alive";

    /**
     * Energy needed to swim in a block of time.
     */
    private static final int ENERGY_TO_SWIM = 2;
   
    /**
     * The crocodile is born "alive".
     * Then it dies, becoming a "dead" corpse.
     */
    private static final String DEAD = "dead";

   
    /**
     * Lowest possible energy needed for a baby to survive.
     */
    private static final int BABY_MIN_ENERGY = 700;
   
    /**
     * Maximum energy that a baby can store.
     */
    private static final int BABY_MAX_ENERGY = 2000;

   
    /**
     * Energy needed to look for food once.
     */
    private static final int ENERGY_TO_LOOK_FOR_FOOD = 1;
   
    /**
     * Energy expended to eat once.
     */
    private static final int ENERGY_TO_EAT = 1;
   
    // Concept example: final. since it is a constant
    // Concept example: static. since only one value is needed
    //                         irrespective of number of object instances
    /**
     * String constant - used to indicate the direction crocodile is facing.
     */
    private static final String RIGHT = "right";

    /**
     * String constant - used to indicate the direction crocodile is facing.
     */
    private static final String LEFT = "left";

    /**
     * String constant - used to indicate the direction crocodile is facing.
     */
    private static final String UP = "up";

    /**
     * String constant - used to indicate the direction crocodile is facing.
     */
    private static final String DOWN = "down";

    /**
     * Name of species
     */
    private static final String SPECIES = "Crocodile";

    /**
     * Row-wise location of the crocodile
     */
    private int row;

    /**
     * Column-wise location of the crocodile
     */
    private int column;

    /**
     * Is the catfish dead or alive?
     */
    private String deadOrAlive;
   
    /**
     * Amount of energy the crocodile has.
     */
    private int energy;

    /**
     * Age expressed as blocks of time lived
     */
    private int age = 0;

    /**
     * Name of this crocodile.
     */
    private final String name;

    /**
     * The simulation to which this crocodile belongs.
     * This is needed so the crocodile can send a message
     * to simulation and ask
     * for prey (or predator) in the neighboring locations.
     * Prey is food. Food is good!
     */
    private Simulation simulation;

    /**
     * Minimum energy level needed to survive.
     * The minimum could increase as the individual grows.
     */
    private int minEnergy;
   
    /**
     * Maximum energy level that the crocodile could carry.
     * The maximum could change as the individual grows.
     */
    private int maxEnergy;
   
    /**
     * Which direction am I facing.
     */
    private String direction;

    /**
     *
     * Number of crocodile created
     */
    private static int nCrocodileCreated = 0;

    /**
     * Constructor. Initialize an crocodile to start life at a specified
     * location with a specified energy. If location is out of bounds,
     * locate the catfish at the nearest edge.
     *
     * @param initialRow - the row at which the crocodile is located
     * @param initialColumn - the column at which the crocodile is located
     * @param initialSimulation - the simulation that the catfish belongs to
     */
    public Crocodile(
        int initialRow,
        int initialColumn,
        Simulation initialSimulation) {

            name = SPECIES + nCrocodileCreated;
          
            simulation = initialSimulation;
          
            deadOrAlive = ALIVE;
          
            row = initialRow;
            column = initialColumn;
          
            minEnergy = BABY_MIN_ENERGY;
            maxEnergy = BABY_MAX_ENERGY;
          
            age = 0;
            direction = RIGHT;
          
            do{
                energy = (nextInt(BABY_MIN_ENERGY)*2)+100;
            }while(energy<BABY_MIN_ENERGY || energy>BABY_MAX_ENERGY);  
          
            ++nCrocodileCreated;      
    }
   
    /**
     * Get the row at which the crocodile is located
     *
     * @return - the row of the crocodile's location.
     */      
    public int getRow() {
        return row;
    }

    /**
     * Get the column at which the crocodile is located
     *
     * @return - the column of the crocodile's location.
     */      
    public int getColumn() {
        return column;
    }

    /**
     * Get the crocodile's age
     *
     * @return the age of the crocodile expressed in blocks of time
     */
    public int getAge() {
        return age;
    }

    /**
     * Color of the crocodile expressed in hex notation.
     * For example, the "green-est" color is "#00FF00",
     * "blue-est" is "#0000FF", the "red-est" is "#FF0000".
     *
     * @return the rgb color in hex notation. preceded by a pound character '#'
     */
    public String getColor() {
        return "#FFFFFF"; // default is white.
    }

    /**
     * Get the name of this crocodile
     *
     * @return the name of the crocodile.
     */
    public String getName() {
        return name;
    }
   
    /**
     * Get the minimum energy needed to live.
     *
     * @return the minimum energy needed for the crocodile to live.
     */
    private int getMinEnergy() {
        return minEnergy;
    }
   
    /**
     * get the maximum energy that the crocodile can carry.
     *
     * @return the maximum energy the crocodile can carry.
     */
    private int getMaxEnergy() {
        return maxEnergy;
    }
   

    /**
     * Get the energy currently carried by the crocodile.
     *
     * @return current energy level of the organism
     */
    public int getEnergy() {
        return energy;
    }

    /**
     * Sets energy level.
     * If new energy level is less than minimum energy level, the organism dies.
     * New energy level is capped at maximum energy level.
     */
    private void setEnergy(int newEnergy) {
        if (newEnergy<minEnergy)
        {
            die();
        }
        else
        {
            if(newEnergy>=maxEnergy)
            {
                energy = maxEnergy;
            }
            else
                energy = newEnergy;
        }
        energy = newEnergy;
      
    }

    /**
     * Die: Change the deadOrAlive to DEAD.
     */
    public void die() {
        deadOrAlive = DEAD;
    }

    /**
     * Is the crocodile dead?
     *
     * @return <code>true</code> if dead. <code>false</code>, otherwise.
     */
    public boolean isDead() {
        return (deadOrAlive == DEAD);
    }

    /**
     * Get the direction faced by the crocodile.
     *
     * @return the facing direction.
     */
    private String getDirection() {

        return direction;
    }

    /**
     * Is the crocodile hungry?
     *
     * @return True, if hungry. False, otherwise.
     */
    private boolean isHungry() {
      
        // Hungry, if current energy level is less than twice the
        // amount needed for survival.
        if(energy >= minEnergy*2)
            return false;
        else{  
            return true;
        }
    }

    /**
     * Move the crocodile to a new row, if new row is within lake bounds.
     *
     * @param newRow - the row to move to.
     * @return the row moved to. Lake boundary limits movement. -1, if dead.
     */
    private int moveToRow(int newRow) {
      
        if (newRow < row) direction = LEFT;
        if (newRow > row) direction = RIGHT;
        row = newRow;
        return row;
    }

    /**
     * Move the crocodile to a new column, if new column is within lake bounds.
     *
     * @param newColumn - the column to move to.
     * @return the column moved to. Lake boundary limits movement.
     */
    private int moveToColumn(int newColumn) {
      
        if (newColumn < column) direction = DOWN;
        if (newColumn > column) direction = UP;
        column = newColumn;

        return column;
    }

    /**
     * This individual belongs to the crocodile species.
     *
     * @return The string indicating the species
     */
    public String getSpecies() {
        return SPECIES;
    }

    /**
     * crocodile should be displayed as an image.
     *
     * @return a constant defined in {@link Simulation#IMAGE Simulation} class
     */
    public String getDisplayMechanism() {
        return Simulation.IMAGE;
    }

    /**
     * Get the image of the crocodile
     *
     * @return filename of Crocodile image
     */
    public String getImage() {
      
        if (direction == LEFT) return "/Crocodile-left.gif";
        if (direction == RIGHT) return "/Crocodile-right.gif";
        if (direction == UP) return "/Crocodile-up.gif";
        if (direction == DOWN) return "/Crocodile-down.gif";
      
        return "/Crocodile-right.gif";
    }


    /**
     * Look for food in the neighborhood. Consume some energy in the process.
     *
     * @return a neighboring algae that is food.
     */
    private Crocodile lookForFoodInNeighborhood() {
        int neighborIndex;
        // Looking for food consumes energy.
        setEnergy(getEnergy() - ENERGY_TO_LOOK_FOR_FOOD);

        if (isDead()) {

            return null;
        }

        Vector neighbors =
            simulation.getNeighbors(getRow(), getColumn(), 1);

        for (neighborIndex = 0;
            neighborIndex < neighbors.size();
            ++neighborIndex) {
            if (neighbors.get(neighborIndex) instanceof Catfish) {

                return (Crocodile) neighbors.get(neighborIndex);
            }
        }      
        return null;
    }

   

    /**
     * Crocodile lives its life. It may lose or gain energy.
     */
    public void liveALittle() {
      
        if (energy<=minEnergy){
            die();
        }
        ++age;
      

        minEnergy += nextInt(10);
        maxEnergy += nextInt(10);
        swimIfPossible();
      
      
    }
    /**
     * Swim to a new location if possible.
     * Consumes some energy.
     */
     private void swimIfPossible() {
       
         if (energy>=0){
            energy = energy - ENERGY_TO_SWIM;  
        }
        moveToColumn(nextInt(10));
        moveToRow(nextInt(10));
      
     }
   
     public int nextInt(int w){
         int a;
         a = (int)((double) Math.random()*w);
         return a;
     }

}
 


EX 6

Practical quiz 6

Link to JAVA FILE (OOGallery.java) : http://depositfiles.com/files/hh42l043r

Practical 3

SAVE IT AS WelcomeWithPassword.html


<HTML>
<HEAD>
<TITLE>Quiz Practical 3</TITLE>
</HEAD>
<BODY bgcolor='blue'>

<FORM action="/servlet/Welcome" method="post">
<CENTER>
<H2>PRACTICAL QUIZ 3: Welcome</H2>
<BR>
<BR>
<BR>
<LABEL><I>Login Name:</I><INPUT type='text' name='Name'></LABEL>
<BR>
<BR>
<LABEL><I>Password:</I><INPUT type='Password' name='password' value='' size='6' maxlength='6'></LABEL>
<BR>
<BR>
<BR>
<INPUT name='button' type='submit' value='Done'></CENTER>
</FORM>
</BODY>
</HTML>
 

EX 2

save it and upload it as exercise2.html




<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>

<HTML>
<HEAD>
<TITLE>MI PRIMERA PAGINA</TITLE>
</HEAD>
<BODY>

<H1>Este es un encabezado H1.</H1>

<H2>Este es un encabezado H2.</H2>

<H6>Este es un encabezado H6.</H6>

Esta es una regla horizontal.
<HR WIDTH=650 ALIGN=LEFT>

<EM>Este enunciado se muestra con ÉNFASIS.</EM>

<PRE><STRONG>Este enunciado se muestra con texto FUERTEMENTE ENFATIZADO.</STRONG></PRE>


<U>Este enunciado se muestra con texto SUBRAYADO.</U>

<P><FONT COLOR='#FFOOOO'>Este enunciado tiene la letra de color rojo.</FONT><P>

<P>La siguiente es una lista ORDENADA o NUMERADA.</P>
<OL>
<LI>Este es el elemento 1</LI>

<LI>Este es el elemento 2</LI>

<LI>Este es el elemento 3</LI>

<LI>Este es el elemento 4</LI>
</OL>

<A HREF='http://www.icarnegie.com/images/logo_big.gif'>Esta Liga muestra una imagen</A>

<P>Las siguientes son ligas requeridas para la Parte B</P>


<A HREF='http://www.sedonline.com/export.asp'>Corporacion</A>
<BR>
<A HREF='http://www.utc.edu'>Universidad</A>
<BR>
<A HREF='http://www.lobosgrisesuad.com/Calendario.php'>Equipo</A>
<BR>
<A HREF='http://www.asociacion-sinfonica.org/p/conciertos/temp2005-01.html'>Arte</A>
<BR>
<A HREF='http://farm1.static.flickr.com/252/448874416_22f5ef3bc7.jpg'>Washington</A>



</BODY>
</HTML>