Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

write two method called findIndex and findLastIndex that search for a number in an array. they should take an int array and an int as parameters. findIndex should return the index of the first instance of the number in the array. findLastIndex should return the index of the last instance of the number in the array. They both should return -1 if the number is not found. Do not use any library methods


Use method overriding to write two methods called printArray. On should take an int array and the other should take a double array. Both should print the array they are given as an argument


*Based on answers A-E, which option is correct? 


3. Given the following code, which is a n "instance variable" of the "Fruits" class?


class Fruits

{

public weight;

Fruits(double w) { weight = w; int height = 10}

public setHeight() { int h = 15; }

}

A. weight

B. height

C. w

D. h

E. All of the options


*Based on answers A-E, which option is correct?


2. Assuming there exists a Java class named "Fruits", which can create an instance named "f1"

of the "Fruits" class that calls the default constructor for initialization?


A. Fruits(f1) = new Fruits();

B. Fruits f1 = new();

C. Fruits f1 = new Fruits();

D. Fruits *f1 = new Fruits();

E. Fruits *f1 = new Fruits;


Suppose that overSpeed and fine are double variables. Assign the value to fine as follows: If 0 < overSpeed <= 5, the value assigned to fine is $20.00; if 5 < overSpeed <= 10, the value assigned to fine is $75.00; if 10 < overSpeed <= 15, the value assigned to fine is $150.00; if overSpeed > 15, the value assigned to fine is $150.00 plus $20.00 per mile over 15.


Suppose that sale and bonus are double variables. Write an if...else statement that assigns a value to bonus as follows: If sale is greater than $20,000, the value assigned to bonus is 0.10; If sale is greater than $10,000 and less than or equal to $20,000, the value assigned to bonus is 0.05; otherwise, the value assigned to bonus is 0.


Correct the following code so that prints the correct message


if (score>=60)

System.out.println("You Pass.");

else;

System.out.println("You Fail.");


Write Java statements that output Democrat if the party affiliation code is 'D', Republican if the party affiliation code is 'R; and independent otherwise.


Give an example of a "while" loop, then provide the equivalent "do-while" loop and "for" loop. Then give a different example of a do-while loop, along with the equivalent while loop and for loop. Finally, give an example of a for loop, along with the equivalent while loop and do-while loop. 


*Based on answer choices A-E, what is the code's output?


10. Given the following code, the output is __.


class Apple

{

int i;

Apple(int n) { i = n; }

}

class Sample

{

int j;

private Sample()

{

Apple a1 = new Apple(2);

a1.i++;

j = a1.i;

}

public static void main(String args[])

{

Sample s1 = new Sample();

System.out.println(s1.j);

}

}


A. 5

B. 4

C. 3

D. 2

E. 1


LATEST TUTORIALS
APPROVED BY CLIENTS