Underline the valid method headings assuming they exist
inside a class.
public void f( )
public void main( String args )
private RationalNumber()
public double sum( int left, right )
public integer String( int n )
public double void f2( )
public BankAccount bankAccount( )
public void functionOne( int a, int b )
UML stands for the Unified Modeling Language
Public(+)
Private(-)
Once we have implemented the solution, we are not
done with the problem because
The solution may not be the best (most efficient) ,
The solution may have errors and need testing and fixing
before we are done,
The solution may, at a later date, need revising to handle
new specifications,
The solution may, at a later date, need revising because of
new programming language features
Which of the following would not be considered an
algorithm?
A recipe, A computer program, Pseudocode , Travel
directions
Having multiple class methods of the same name
where each method has a different number of or type of
parameters is known as Method overloading
The type char is a primitive data type TRUE
The type String is a primitive data type FALSE
To define a constant called MAX_MARKS in the
class which of the following statement is correct:
public static final int MAX_MARKS = 100;
k holds a value of the type int, then the value of the
expression... k <= 10 || k > 10 Must be true
Write a method called median that receives in three
integers and returns the median value?
public int median(int num1, int num2, int num3)
Write the constructor, which is passed the player’s
name and position.
Public BaseballPlayer(String newName, String
newPosition)
{……….}
Write a toString method that returns the player’s
name, position and batting average formatted to have 1
digit to the left of the decimal and 3 digits to the right of the
decimal. Assume DecimalFormat has been imported.
Public String toString()
{
DecimalFormat df = new DecimalFormat
(“0.000”);
Return name + “\t”+poition + “\t” +
df.format(battingAverage);
}
Student
-name: String = “ ? ”
-address: String = “ ? ”
-idNumber: int = 0
+toString(): String
+submitHW(): boolean
int n = 5;
for( int j = 1; j <= n; j+=3 )
{ System.out.print( "Hello " );
int k=j;
while (k < n)
{
System.out.println(“Good
Morning”);
}
k++;
} j--;
Hello Good Morning
Good Morning
Good Morning
Good Morning
Hello Good Morning
Good Morning
Hello
int n = 979;
for( int j = 0; j <= n; j++ )
{
System.out.print( "Hello " );
}
980 TIMES
public int median( int num1, int num2, int num3)
{
if ( num1 >= num2 && num1 <= num3 )
return num1;
else if ( num1 <= num2 && num1 >= num3 )
return num1;
else if ( num2 >= num1 && num2 =< num3 )
return num2;
else if ( num2 <= num1 && num2 >= num3 )
return num2;
else
return num3;
}
What is the output of the
following code fragment ?
String name;
int i;
boolean startWord;
name = "Richard M. Nixon";
startWord = true;
for (i = 0; i < name.length(); i++)
{
if (startWord)
System.out.println(name.charAt(i));
if (name.charAt(i) == ' ')
startWord = true;
else
startWord = false;
} R
M
N
int j = 1;
while( j <= 11 )
{
System.out.print( "Hello " );
} j = j + 3; 4 TIMES
int j = 1;
int n = 5;
while( j <= n )
{
System.out.print( "Hello " );
} n--; 5 TIMES