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

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)?


Weekends


Given two dates D1 and D2, write a program to count the number of Saturdays and Sundays from D1 to D2 (including D1 and D2).


The date in string format is like "8 Feb 2021".Input




The first line of input will contain date D1 in the string format.


The second line of input will contain date D2 in the string format.Output




The output should be a single line containing two integers separated by space.Explanation




For example, if the given dates are "25 Jan 2021" and "14 Feb 2021", the Saturdays and Sundays dates from "25 Jan 2021" to "14 Feb 2021" are


"30 Jan 2021" is a Saturday


"31 Jan 2021" is a Sunday


"6 Feb 2021" is a Saturday


"7 Feb 2021" is a Sunday


"13 Feb 2021" is a Saturday


"14 Feb 2021" is a Sunday


So the output should be


Saturday: 3


Sunday: 3


Sample Input 1


25 Jan 2021


14 Feb 2021


Sample Output 1


Saturday: 3


Sunday: 3




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;

}

}


3. The Car class (subclass) inherits the attributes and methods from the Vehicle class (superclass). And every car has model. Please also add toString method to the Car class to print out the brand, and model of the car.

Class Vehicle {

protected String brand; // Vehicle attribute

Vehicle() // Vehicle constructor

{

Brand = “Ford”;

}

public void honk() { // Vehicle method

System.out.println("Tuut, tuut!");

}

}

Please help write the Car class. (10 marks)


Write a subroutine named "printDayofWeek" that will output the day of the week for a given number. Use Swtich-case. For example, the command "1” would output “Sunday”. (10 marks)


1. Write pseudo code that prints the smallest value among a list of numbers. (10 marks) 


Write an Algorithm to input these ten values and get the average temperature for that day. if the average temperature value is in between 970 Fahrenheit and 990 Fahrenheit then display the message “Your body temperature is normal…”. If it is more than 100.40 Fahrenheit then display the message “You have a fever caused by an infection or illness…”


LATEST TUTORIALS
APPROVED BY CLIENTS