Question: Identify all errors in the following class. public class SampleClass ; { private String phoneNumber; // a ten-digit phone number (e.g. 1234567890) private double batteryLife;

Identify all errors in the following class.

public class SampleClass ;

{

private String phoneNumber; // a ten-digit phone number (e.g. 1234567890)

private double batteryLife; // in the range between 0.0 and 1.0

(one error)

public SampleClass( )

{

phoneNumber = 123467890

batteryLife = 0.0

}

(two errors)

public void setPhoneNumber( String n )

{

if ( n.length = 10)

{

n = this.phoneNumber ;

}

}

(two errors)

public void getPhoneNumber( )

{

return this.phoneNumber;

}

(one error)

public boolean chargeComplete( double charge )

{

if ( charge = 1.0)

{

return true;

}

else

{

return false;

}

}

(one error)

}

Tracing code

In plain English (ONE SENTENCE), state what the following code fragment does.

public int sum ( int num )

{

int total = 0;

for (int n = 0; i < num ; n++)

{

total = total + n;

}

return total;

}

What will be the output for the following code fragment?

Code fragment

Output

String zipcode = "01234";

String str = "";

int n = zipcode.length( ) - 1;

while( n >= 0 )

{

str = zipcode.charAt( n ) + str;

n = n - 1;

}

System.out.println( str );

What will be the possible range of integers printed for each System.out.println statement below?

Statement

Possible range of integers

Random r = new Random ( );

System.out.println( r.nextInt( ) );

System.out.println( r.nextInt ( 2 ) + 1 );

System.out.println( r.nextInt ( 3 + 10 ) );

System.out.println( r.nextInt ( 6 ) + 1 );

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!