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

Samuel owns a shoe factory where there are N different machines operated for N different purposes. Each machine has its own motor. In order to avoid resonance, the rotation speed of any 2 machines should at least differ by 2 units. The rotation speed can only be in integer units and the maximum rotation speed of any motor is X units. Given minimum rotation speed of any motor to be 1 unit, you have to help Sam find out the number of different ways he can configure the speed of the motor. Input Specification: input1: N, denoting the number of machines. input 2X, denoting the maximum speed of the motor. Output Specification: Your function should return the total number of configuration modulus 10^4.




Implement a class Car as described below. A Car shall have a brand, model and mileage. The class Car should have a proper constructor to set the brand and model of a car. A new car should have mileage as 0 km. The class Car provides public method getBrand and getModel to access the car’s brand and model respectively. The class Car provides a public method drive to increment the mileage by 1 km. (10 marks)


Write a main()routine that uses the subroutine that you wrote for part (a) to output 10 lines of stars with 1 star in the first line, 2 stars in the second line, and so on, as shown below. ( 6 marks)

*_*_*_*_*_*_*_*_*_*

*_*_*_*_*_*_*_*_*

*_*_*_*_*_*_*_*

*_*_*_*_*_*_*

*_*_*_*_*_*

*_*_*_*_*

*_*_*_*

*_*_*

*_*


Write a subroutine named "stars" that will output a line of stars to standard output. (A star is the character "*".) The number of stars should be given as a parameter to the subroutine. Use for loop. For example, the command "stars(10)" would output (6 marks) *_*_*_*_*_*_*_*_*_* 


Write pseudo code that print the largest value among a list of numbers. 


7. Please complete the following codes (4 marks)

public class TestArray {

public static void main(String[] args) {

// create and initialize an array ‘myList’ with 4 elements. The values are the 4 elements are into 1.9,2.9,3.4 and 3.5

_______________________________

// Print all the array elements

for (double element: myList) {

System.out.println(element);

}

}

}

What is printed on execution of these methods? 


Consider the following program written in Java to answer this

Question:

1. import java.util.*;

2. class Arraylist

3. {

4. public static void main(String args[])

5. {

6. ArrayList obj = new ArrayList();

7. obj.add("A");

8. obj.add("B");

9. obj.add("C");

10. obj.add("D");

11. System.out.println(obj);

12. }

13. } What would be the output of the statement when the program is executed? 


What is the result of the following program?

Consider the following code fragment

Rectangle r1 = new Rectangle();

r1.setColor(Color.red);

Rectangle r2 = r1;

r2.setColor(Color.blue);

After the above piece of code is executed, what are the colors of r1 and r2 (in this order)?


Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?

A. Public

B. Protected

C. Private

D. No Modifier


Try to refactor below codes for computing score (underlined part) with extract methods

public class Customer

{

void foo()

{

int a, b, c, xfactor;

int score; Scanner myInput = new Scanner(System.in);

a = myInput.nextInt();

b = myInput.nextInt();

c = myInput.nextInt();

xfactor = myInput.nextInt();

System.out.println(“Computer score:”);

// Compute score score = a*b+c;

score *= xfactor;

}

}


LATEST TUTORIALS
APPROVED BY CLIENTS