• Post Reply Bookmark Topic Watch Topic
  • New Topic

I need help answering the programming questions from my study guide please.  RSS feed

 
Shaylen Patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. Consider the array:
s[ 0 ] = 7
s[ 1 ] = 0
s[ 2 ] = -12
s[ 3 ] = 9
s[ 4 ] = 10
s[ 5 ] = 3
s[ 6 ] = 6
The value of s[ s[ 6 ] - s[ 5 ] ] is:
a. 0.
b. 3.
c. 9.
d. 0.

2. Consider the program below:
public class Test
{
public static void main( String[] args )
{
int[] a;
a = new int[ 10 ];

for ( int i = 0; i < a.length; i++ )
a[ i ] = i + 2;
int result = 0;
for ( int i = 0; i < a.length; i++ )
result += a[ i ];
System.out.println( "Result is: "+ result );
} // end main
} // end class Test

The output of this program will be:
a. Result is: 62.
b. Result is: 64.
c. Result is: 65.
d. Result is: 67.

Analyze the following code (This is tricky!):
public class Circle {
public static int result1, result2;

public static void main(String [ ] args) {
int radius1 = 3;
int radius2 = 1;
twoCircles(radius1, radius2);
System.out.println(“The area of circle 1 with radius “ + radius1+” is “ + result1);
System.out.println(“The area of circle 2 with radius “ + radius2+” is “ + result2);
}

public static void twoCircles(int radius2, int radius1) {
radius1++;
radius2 *= radius1;
result1 = Math.PI * Math.pow(radius1,2);
result2 = Math.PI * Math.pow(radius2,2);
System.out.println(“The area of circle 1 with radius “ + radius1+” is “ + result1);
System.out.println(“The area of circle 2 with radius “ + radius2+” is “ + result2);
}
}

3. What radius1 is output in the main method?
a. 1
b. 2
c. 3
d. 4
e. none of the above

4. What radius2 is output in the method?
a. 1
b. 2
c. 3
d. 4
e. none of the above

5. What radius1 is output in the twoCircles method?
a. 1
b. 2
c. 3
d. 4
e. none of the above

6. What radius2 is output in the twoCircles method?
a. 1
b. 2
c. 3 d. 4
e. none of the above

Analyze the following code:
public class Color {
private int red(r); //red hue
private int g; //green hue
private int b; //blue hue

public Color( ) {
red = 0;
g = 0;
b = 0;
}
}

7. True or False: The Color constructor is an example of an overloaded constructor?

8. If I have instantiated a Color object as follows:
Color color1 = new Color();

Which would properly call an Accessor method for the red instance variable
a. color1 = getR( );
b. int rValue = color1.toR( );
c. int rValue = color1.getR();
d. int rValue = getR(color1);

9. Say I want a specialized mutator method, setColors, that updates all three colors.
Which of the following methods would do this?
a. public int setColors( ) {
a. return red + b + g;
}

b. public void setColors(int newR, int newG, int newB) {
a. red = newR; g = newG; b = newB;
}
c. public setColors(int newR, int newG, int newB) {
a. red = newR; g = newG; b = newB;
}

d. public int setColors(int newR, int newG, int newB) {
a. red = newR; g = newG; b = newB;
}
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't even want to scramble the question numbers so it wouldn't look like you were just copy pasting your homework?
 
Shaylen Patel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are questions from the study guide my professor gave us. She did not give us the answers.
 
Paweł Baczyński
Bartender
Posts: 2074
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shaylen Patel wrote:These are questions from the study guide my professor gave us. She did not give us the answers.

Maybe because she wants you to learn and answer them on your own?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What they mean is, you should show us the answers you have, and we shall see whether we agree. You may have to explain our answers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!