1.    Briefly explain one major advantage an if statement has over a switch statement and on significant advantage a switch statement has over an if statement. If there are different conditions or complex condition, use if statement over switch. If you are switching on the value of a single variable then use a switch every time, it’s what the construct was made for. 2. Which of the following will cause an error message? I. double x = 22.5;  int y = x; II. double x = 22.5   int y = (int) x; III. int x = 25;   double y = x; A.    I only B.    II only C.    III only D.    I and II only E.    I and III only 3. List the three major looping constructs in Java and briefly explain the unique situation each is designed for. Three Looping constructs in Java are: •For statement – executes group of Java statements as long as the boolean condition evaluates to true. it is pre test loop the for loop is usually used when you need to iterate a given number of times. for(int i = 0; i < 100; i++) { ...//do something for a 100 times. } •While statement -The while loop is usually used when you need to repeat something until a given condition is true. The condition is determined at run time: inputInvalid = true; while(inputInvalid) { //ask user for input invalidInput = checkValidInput(); } •Do while statement - A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. The syntax of a do...while loop is: do { //Statements }while(Boolean_expression); 4. What value would be output by the code segment below? int x = 6 – 3 * 10 / 8 % 3; System.out.println( x ); A.    -1 B.    0 C.    6 D.    -10 E.    5 5.  Briefly explain one significant advantage of using a get method to obtain the value of an instance variable vs reading the variable directly. A get method can compute a value from several fields and return that value. This value cannot be calculated if variable is accessed directly. 6. Consider the following code segment. int value = 17; while ( value < 25 ) { System.out.println( value ); value++; } What are the first and last numbers output by the code segment? A.    17  24 B.    17  25 C.    18  24 D.    18  25 E.    18  26 7. Briefly explain the difference between a class instance variable and a method variable. Instance variables belong to an instance of a class. Another way of saying that is instance variables belong to an object, since an object is an instance of a class. Every object has its own copy of the instance variables. method variables are local in method scope and they are not visible or accessible outside their scope which is determined by {} while instance variables are visible on all part of code based on their access modifier e.g. public , private or protected 8. Consider the following code. public static void myFunc( int num ) { int type1 = 0; int type2 = 0; int type3 = 0; for ( int i = 1; i <= num; i++ ) { if ( (i % 2 == 0 ) || ( i % 5 == 0 ) ) type1++; if ( i % 2 == 0 ) type2++; if ( i % 5 == 0 ) type3++; } System.out.println( type1 + "t" + type2 + "t" + type3 ); } What is displayed as a result of the function call  myFunc( 50 )? A.    5   20   5 B.    5   25   10 C.    30   25 10 D.    5   20   15 9. I want to create an array named myNumbers, of whole numbers which will hold the numbers zero through 10. Write a code snippet which will create and initialize this array. int myNumbers[]= {0,1,2,3,4,5,6,7,8,9,10}; 10. Consider the following classes. public class Parent { private int pData; public Parent() { pData = 0; } public Parent( int val ) { pData = val; } } public class child extends Parent { public Child() { super( 10 ); } Which of the following statements will produce a complier error? A.    Parent p = new Parent(); B.    Parent p = new Parent( 3 ); C.    Parent p = new Child(); D.    Child c = new Child(); E.    Child c = new Child( 5 ); 11. Write a properly formatted if statement which checks if the contents of the String variable myName is the...

Looking for solution of this Assignment?

WHY CHOOSE US?

We deliver quality original papers

Our experts write quality original papers using academic databases.We dont use AI in our work. We refund your money if AI is detected  

Free revisions

We offer our clients multiple free revisions just to ensure you get what you want.

Discounted prices

All our prices are discounted which makes it affordable to you. Use code FIRST15 to get your discount

100% originality

We deliver papers that are written from scratch to deliver 100% originality. Our papers are free from plagiarism and NO similarity.We have ZERO TOLERANCE TO USE OF AI

On-time delivery

We will deliver your paper on time even on short notice or  short deadline, overnight essay or even an urgent essay