LCCC Course CIS 210 - Java Programming

Study Guide for Test 4

1. In the statement: Ship canoe = new Ship(); identify the following parts (i.e. are they variables, classes, constructors, primitives, objects, keyword, interfaces, etc?)

  • Ship
  • canoe
  • Ship()
  • new Ship()
  • Ship canoe
  • =


2. Write a for loop that will print out the numbers 1 to 25.

 

3. Rewrite the declarations using "standard" naming conventions.

  • public void GetBoats()
  • public class DECK
  • public int Setcard(Card C)
  • private int TopCard;
  • private boolean donewithLoop;

 

4. Given the following class, write the methods to set the paper color and get the paper color

public class PaperDolls
{

private Color paper;

/** write the method to get the color of paper.
You DON'T have to use all lines*/




/** you write the method to set the paper color */


} // PaperDoll class

 

5. Given the following method, what would the final array A contain?

public void myMethod()
{

int j = 0;
int A[] = new int[4];

// The array A contains at the start:

A[0] = 5; A[1] = 2; A[2] = 7; A[3] = 3;

for (int j=0; j < 3; j++)
{

if (A[j] < A[j+1])
{

int temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;

} // if

} // for

} // myMethod()

 

6. Write the three questions needed when designing a method:

7. Writhe the five questions needed when designing a class:

8. Write the three steps for loop control:

9. Circle where 10 syntax errors occur in the following program.

public class Ship()
{

private int sailors;
private boolean scurvy = = true;

public getSailors()

return sailors

}

public void setSailors
{

sailors = 5;

};

public void main(String argv[])
{

System.out.println( "# of sailors is " + number);

}

};

10. Given the following short program snippets, determine the value of the variable (show memory map).

int x = 1; int x = 10/3; int x = 5;
x--; if (x <= 3) if (x == 6);
x *= 2; {   {  
    x = 10;   x = 7;
  }   }  
         
int x = 17; for (int j=1; j<4; j++) int x = -5;
x = x % 3; {   while (x < 1)
x++; int x = j - x;   x++;
  }      
         

 

www.lc.edu

Last Updated: January, 2011