Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Arrays For the questions below: Assume this Box class: public class Box { double

ID: 3683719 • Letter: A

Question

Arrays

For the questions below: Assume this Box class:

     public class Box

     {

        double length;

        double width;

        double height;

     Box(double l, double w, double h)

     {

         length = l;

         width = w;

          height = h;

     }

     double volume( )

     {

         return length * width * height;

     }

    }

Write the statement to instantiate an Box obindexect, blueBox, with a length of 6, width of 4, and height of 2.

Write a statement to output the volume of the blue box.

Override constructor to class Box for a cube, which only accept 1 parameter, side.

Write a statement to instantiate a cube with a length of 3, width of 3, and height of 3.

Add a method FindArea to find area of box, which accept length and width.

What output is produced by the following code fragment?

ArrayList<String> names = new ArrayList<String>();

names.add(“Betty”);

names.add(1, “Chet”);

names.add(1, “Don”);

For the questions below, assume values is an obindexect of ArrayList<Integer> that is currently filled to capacity, with the following values:

9, 4, 12, 2, 6, 8, 18

What is returned by values.get[3]?

What is the value of values.size()?

9.    What output should be generated after adding two statements:

values.add(2,20);

   values.remove(4);

How you can find the max number from values list? Give the main code.

Array  

To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do

A) String names = {"Huey", "Duey", "Louie"};

B) String[ ] names = {"Huey", "Duey", "Louie"};

C) String[ ] names = new String{"Huey", "Duey", "Louie"};

D) String names[3] = {"Huey", "Duey", "Louie"};

E) String names; names[0] = "Huey"; names[1] = "Duey"; names[2] = "Louie";

Describe what problem occurs in the following code. What modifications

should be made to it to eliminate the problem?

int[] numbers = {3, 2, 3, 6, 9, 10, 12, 32, 3, 12, 6};

for (int count = 1; count <= numbers.length; count++)

        System.out.println(numbers[count]);

Write an array declaration and any necessary supporting classes to represent Students’ names for a class of 25 students

14.Write code that prints the values stored in an array called names backwards.

For the questions below, assume values is an int array that is currently filled to capacity, with the following values:

9, 4, 12, 2, 6, 8, 18

15. Which of the following loops would adequately add 1 to each element stored in values?

A) for (index=1; index<values.length; index++) values[index]++;

B) for (index=0; index<values.length; index++) values[index]++;

C) for (index=0; index<=values.length; index++) values[index]++;

D)   for (index=0; index<values.length-1; index++) values[index]++;

E)   for (index=1; index<values.length-1; index++) values[index]++;

Explanation / Answer

For the questions below: Assume this Box class:

public class Box
{
double length;
double width;
double height;

Box(double l, double w, double h)
{
length = l;
width = w;
height = h;
}

double volume( )
{
return length * width * height;
}

}

Write the statement to instantiate an Box obindexect, blueBox, with a length of 6, width of 4, and height of 2.
Box blueBox = new Box(6, 4, 2);
Write a statement to output the volume of the blue box.

System.out.println("The volume of box is: "+ blueBox.volume());
Override constructor to class Box for a cube, which only accept 1 parameter, side.
Box(double side)
{
length = width = height = side;
}


Write a statement to instantiate a cube with a length of 3, width of 3, and height of 3.
Box cube = new Box(3);

Add a method FindArea to find area of box, which accept length and width.
double FindArea(double length, double width)
{
return length * width;
}


What output is produced by the following code fragment?

ArrayList<String> names = new ArrayList<String>();
names.add(“Betty”);
names.add(1, “Chet”);
names.add(1, “Don”);
Nothing will be printed as output. As there are no print statement. But internally, the elements are stored in the ArrayList in the order:
Betty->Don->Chet.


For the questions below, assume values is an obindexect of ArrayList<Integer> that is currently filled to capacity, with the following values:
9, 4, 12, 2, 6, 8, 18
What is returned by values.get[3]?
2 will be returned.
What is the value of values.size()? 7.
9. What output should be generated after adding two statements:
values.add(2,20); 9, 4, 20, 12, 2, 6, 8, 18
values.remove(4); 9, 20, 12, 2, 6, 8, 18

How you can find the max number from values list? Give the main code.

Array

To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do
A) String names = {"Huey", "Duey", "Louie"};
B) String[ ] names = {"Huey", "Duey", "Louie"};
C) String[ ] names = new String{"Huey", "Duey", "Louie"};
D) String names[3] = {"Huey", "Duey", "Louie"};
E) String names; names[0] = "Huey"; names[1] = "Duey"; names[2] = "Louie";

Describe what problem occurs in the following code. What modifications
should be made to it to eliminate the problem?

int[] numbers = {3, 2, 3, 6, 9, 10, 12, 32, 3, 12, 6};
for (int count = 1; count <= numbers.length; count++)
System.out.println(numbers[count]);

Write an array declaration and any necessary supporting classes to represent Students’ names for a class of 25 students
14.Write code that prints the values stored in an array called names backwards.

For the questions below, assume values is an int array that is currently filled to capacity, with the following values:
9, 4, 12, 2, 6, 8, 18
15. Which of the following loops would adequately add 1 to each element stored in values?
A) for (index=1; index<values.length; index++) values[index]++;
B) for (index=0; index<values.length; index++) values[index]++;
C) for (index=0; index<=values.length; index++) values[index]++;
D) for (index=0; index<values.length-1; index++) values[index]++;
E) for (index=1; index<values.length-1; index++) values[index]++;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote